Mongoose update value only on change

Is there a way in mongoose to update the document only when values ​​change?

Something like

User.findAndUpdateOnChange({query}, data, function(err, user){

}); 

      

I am very new to node js. Any help would be great.

+3


source to share


1 answer


I think you need to use get query first and then compare, if the comparison result is false then use update query. Otherwise not



User.find({'key': 'Value'}).exec(function(err, result){
  if(result.key !== 'your new value'){
    user.update({query}, data, function(err, user){

    })
  }
}    

      

0


source







All Articles