1//pass the {new: true} as the third option, if using mongodb driver use {returnOriginal: true} V--- THIS WAS ADDED
2Cat.findOneAndUpdate({age: 17}, {$set:{name:"Naomi"}}, {new: true}, (err, doc) => {
3 if (err) {
4 console.log("Something wrong when updating data!");
5 }
6
7 console.log(doc);
8});
9
1const update = await client.db('database').collection('col').findOneAndUpdate({
2 'param': 'value'
3 }, {
4 $set: {
5 'param': 'newvalue'
6 }
7 }, {
8 returnDocument: 'after',
9 projection: {
10 param: 1
11 }
12 })
13
1
2var oldPLoad = msg.payload;
3delete oldPLoad._id;
4
5msg.payload = [
6 {
7 "_id":msg._id,
8 },
9 {
10 $set:oldPLoad
11 },
12 {
13 upsert: true,
14 returnOriginal:false
15 }
16];