How can I check if the remove-method of a Mongoose model really has removed something?
MyModel.remove({_id: myId}, function(err, entry) {
if(entry == null) next(new Error("ID was not found.")); // this doesn't work
}
Can I check how many documents were removed?
In the Mongo-Documentation kristina1 write in a comment:
If you call db.runCommand({getLastError:1}) after a remove and the "n" field will tell you how many documents were deleted.
But I don't know how to do this with Mongoose.
The second parameter to the remove
callback is a number containing the number of documents removed.
MyModel.remove({_id: myId}, function(err, numberRemoved) {
if(numberRemoved === 0) next(new Error("ID was not found."));
}