Mongoose Version 3.x vs 4.x Changes
FindOneAndUpdate
Mongoose Version 3.x
[code lang=”js”]
var query = { name: ‘old Name’ };
var updates = { name: ‘new Name’ };
var options = { new: false};
Person.findOneAndUpdate(query,updates,options,callback)
[/code]
To return the orginal document rather than the updated document… set the option “new” to false. Defaults to true;
Mongoose Version 4.x
[code lang=”js”]
var query = { name: ‘old Name’ };
var updates = { name: ‘new Name’ };
var options = { new: true};
Person.findOneAndUpdate(query,updates,options,callback)
[/code]
To return the orginal document rather than the updated document… set the option “new” to true. Defaults to false;
Mongoose 3
– To get promise… first call .exec()
– Person.find({}).exec().then(…);
Mongoose 4
– Queries returned by .find() are promises
– Person.find({}).then(..);
More info:
https://github.com/Automattic/mongoose/wiki/4.0-Release-Notes