node.js - Mongoose and findAndModify -
i use node.js
mongoose
plugin. need try select single document query like:
{ _id: '52261c53daa9d6b74e00000c', someadditionalflag: 156 }
and if , if succeeds change flag value. moreover, find , modify operation needs atomic. please, how achieve using mongoose?
you don't need use findandmodify
don't need original document. can use update
this:
mymodel.update({ _id: '52261c53daa9d6b74e00000c', someadditionalflag: 156 }, { $set: {someadditionalflag: newvalue } }, function(err, numaffected) { ... });
in callback, numaffected
1 if change made, otherwise 0.
Comments
Post a Comment