Mongoose transforms the result of findOneAndUpdate() by default: it returns the updated document.
In Mongoose 4.0, the default value for the new
option of findByIdAndUpdate
(and findOneAndUpdate
) has changed to false
, which means returning the old doc (see #2262 of the release notes). So you need to explicitly set the option to true
to get the new version of the doc, after the update is applied:
Model.findByIdAndUpdate(id, updateObj, {new: true}, function(err, model) {...
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With