Reputation: 15
I want to update multiple values in a single document in one mongoose call. Is this possible?
I have something similar to this:
update = {$inc : { numShown : 1 }, $inc : { secondField.subField : 1 }};
options = {};
MyModel.findByIdAndUpdate(req._id, update, options, function(err){
if(err){ return console.error(err);}
}
It runs, but doesn't update anything.
Upvotes: 1
Views: 228
Reputation: 311835
You need to combine the two $inc
values into a single object and quote the dotted key:
update = { $inc : { numShown : 1, 'secondField.subField' : 1 } };
Upvotes: 3