I am trying to update a specific subfield in a mongoDB document and decided to first find the object in question and then save the updated one. For some reason, the save option seems to ignore my changes.
I have one object in my collection and it matches the following scheme:
var tschema= mongoose.Schema({
a: Object
})
var t = db.model('tongoose',tschema);
t.findOne({},function(err,obj){
console.log(obj.a);
obj.a[1]=1;
console.log(obj);
obj.save(function(err,real){
console.log(real);
});
});
But when I go back to mongoDB and look at the saved object, it never shows any changes. Can you tell me what I'm doing wrong?
Great importance.
source
share