Answers for "mongo find one then update"

0

mongodb findoneandupdate return updated

//pass the {new: true} as the third option, if using mongodb driver use {returnOriginal: true}                                                      V--- THIS WAS ADDED
Cat.findOneAndUpdate({age: 17}, {$set:{name:"Naomi"}}, {new: true}, (err, doc) => {
    if (err) {
        console.log("Something wrong when updating data!");
    }

    console.log(doc);
});
Posted by: Guest on May-24-2021
0

mongoid find_one_and_update

Model.where(id: id).find_one_and_update({
    :$inc => {
      payload
    }
  },
  upsert: true,
  return_document: :after
)
Posted by: Guest on December-18-2020

Code answers related to "Javascript"

Browse Popular Code Answers by Language