Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Mongoose findByIdAndUpdate not returning correct model

People also ask

What does Mongoose Findbyidandupdate return?

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) {...