Search code examples
node.jsmongodbmongoosemongoose-models

Mongoose: set single option in Model.remove()


Documentation says about Model::remove() method:

Removes all documents that match conditions from the collection. To remove just the first document that matches conditions, set the single option to true.

The question is how to set this option?

I've tried:

1) Model.remove({code: 55, single: true }, function (err, deleted) {... — no result, because, as I can expect, single in this case is considered as a field, which doesn't exist;

2) Model.remove({code: 55}, {single: true }, function (err, deleted) {TypeError: callback.apply is not a function.

I'm a Mongoose-beginner, thanks in advance for any help.


Solution

  • Oh my, I've found, how to solve it - in source code:

    Model.remove({code: 55}).setOptions({ single: true }).exec(function (err, deleted) {...