James B
James B

Reputation: 15

Multiple updates in one document using mongoose

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

Answers (1)

JohnnyHK
JohnnyHK

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

Related Questions