LearnBoost/mongoose — Issue #633: Add findAndModify to the Model
Author: mlegenhausen
Created: 2011-12-01 09:01:58+00:00
State: open

I use this method really often (for realizing two-phase-commits). I found out there are some work arounds to add this functionality but a official support would be really nice, cause I think it is simply a update method that return the updated document or I am wrong?

The current workaround is:

```
var schema = new mongoose.Schema({ ... });
schema.collection.findAndModify(args, function(error, doc) {
if (err) return cb(err);
if (!doc) return cb(null);
var model = new schema();
model.init(doc, function(err) {
if (err) return cb(err);
return cb(null, model);
});
});
```

Of cause when doing this I can bypass the validation features, but a more important feature for me is that I have all the model methods on the returned doc.

When you don't want to give official support please add it to the documentation.