How to get updated document back from the findOneAndUpdate method?

The Node.js driver documentation doesn't mention a returnNewDocument option for findOneAndUpdate() (which is an option for the MongoDB shell command with the same name).

Instead, it mentions an option called returnOriginal, which defaults to true. Try using that option, setting it to false to return the updated document instead of the original.


To get the updated document after performing the update operation we need to use the option "returnDocument" : "after" along with "returnOriginal" : false.

As per the latest mongodb node driver v3.6 documentation, the usage of returnOriginal is deprecated. But when I try only including "returnDocument" : 'after' without "returnOriginal":false its returning the original record instead of the updated record. Using them both is giving the desired output of updated record instead of the original record. (source : http://mongodb.github.io/node-mongodb-native/3.6/api/Collection.html#findOneAndUpdate)

The option "returnNewDocument" : true is a mongo shell option and may not work in the node driver as per the official mongodb documentation ( mentioned here https://docs.mongodb.com/manual/reference/method/db.collection.findOneAndUpdate/)


If you are seeing this latest 2018, neither returnNewDocument:true nor returnOriginal: false, works. You have to instead set a property called new to true as in {.., new: true} in the option object for your query.