I would like to use findAndModify to atomically increment a field, using Mongoose.
However, the code below throws the error \"TypeError: Object # has no method \'fin
In version 3, the mongoose findOneAndUpdate method exposes mongodb's findAndModify operation. It works like so:
var query = { name: 'Sprinkls' };
var update = { name: 'Sprinkles' };
var options = { new: false };
Cat.findOneAndUpdate(query, update, options, function (err, cat) {
if (err) ..
render('cat', cat);
});
More info here: http://aaronheckmann.tumblr.com/post/48943524629/mongoose-v3-part-2-findandmodify