Answers for "Node.js: “returnNewDocument: true” not working"

1

Node.js: “returnNewDocument: true” not working

// /node-mongodb-native//4.0 driver 
//returnOriginal is Deprecated Use options.returnDocument instead.
returnDocument	'before' | 'after'
When set to 'after',returns the updated document rather than the original
When set to 'before',returns the original document rather than the updated.
The default is 'before'.

const options = { returnDocument: 'after' };
//same for findOneAndReplace
myDataBase.findOneAndUpdate(query, update, options, (err, doc) => {
   if (err) {
          console.log("Something wrong when updating data!");
        }
        else if (!doc.lastErrorObject.updatedExisting && doc.value == null)
          return res.json('no book exists')
  
 // The updated document is held within the value property of the response
        console.log('doc.value');
        console.log(doc.value);
})

//https://stackoverflow.com/a/67909382/918069/
Posted by: Guest on July-31-2021

Code answers related to "Node.js: “returnNewDocument: true” not working"

Code answers related to "Javascript"

Browse Popular Code Answers by Language