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

Popular posts from this blog

html - How to style widget with post count different than without post count -

How to remove text and logo OR add Overflow on Android ActionBar using AppCompat on API 8? -

javascript - storing input from prompt in array and displaying the array -