Hi guys here is the problem:
I have a mongoose schema that looks like this:
TopicSchema = new Schema({
topic_id: {type : String, required: true, index: true, unique: true, trim : true},
title: {type : String, required: true, trim : true},
path: [{topic_id: {type: String, index:true}, title: {type: String}}],
})
As you can see the path property consists of an array that contains objects with two properties: topic_id and title. The problem is that mongodb or mongoose is creating a third field called _id inside those objects when I do an update operation.
Here is how the update looks:
1) Create a javascript array: var path = [{topic_id:"Arrow", title:"Episode 1"}]
2) Update:
Topic.update({_id: topic._id}, {$set: {path: path}}, function(err, updatedTopic){
if(err){ callback(err); console.log("Error while updating: ", topic._id) }
})
When I check the database the path property looks like: {topic_id:"Arrow", title:"Episode 1", _id: Object_id("XXXXXXXX")} As you can see it creates an _id property out of nowhere.
I've tried modifying the model property names, updating through the mongoose .save() and findByIdAndUpdate and I still get the same result.
Thanks for the help.