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' };
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')
console.log('doc.value');
console.log(doc.value);
})