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/