I want to update a document using the inbound form fields from req.body
without having to break them apart and build out a $set
. I have this working just fine. Now I want to add an increment to a field that won't be provided by req.body
, how do I do that?
Here's my current code:
var myproj = req.body; // grab req.body
myproj.foo = 'bar'; // some other random property
Project.update({_id: req.params.project_id }, myproj, { multi: false }, function(err, edited) {...
So how can I add a $inc
to that for a field in the document called version
?
You can combine modifiers in the same update and you can apply your whole myproj
in a single $set
:
Project.update(
{ _id: req.params.project_id },
{ $set: myproj, $inc: { version: 1 } },
{ multi: false },
function(err, edited) {...