Mongoose findByIdAndUpdate not returning correct model
Solution 1:
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) {...