Answers for "findOneAndUpdate in Mongo database"

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

findOneAndUpdate in Mongo database

var oldPLoad = msg.payload;
delete oldPLoad._id;

msg.payload = [
    {
        "_id":msg._id,
    },
    {
        $set:oldPLoad
    },
    {
        upsert: true,
        returnOriginal:false
    }
];
Posted by: Guest on August-13-2021
0

mongodb findoneandupdate return new document

const update = await client.db('database').collection('col').findOneAndUpdate({
      'param': 'value'
    }, {
      $set: {
        'param': 'newvalue'
      }
    }, {
      returnDocument: 'after',
      projection: {
        param: 1
      }
    })
Posted by: Guest on August-12-2021

Code answers related to "findOneAndUpdate in Mongo database"

Code answers related to "Javascript"

Browse Popular Code Answers by Language