Understanding mongoose findOne().remove()

Viewed 8217

As you know, in mongoose, we can remove all users with age 30 like this:

User.find({age: 30}).remove(callback);

Now, replace find() with findOne(), and I think it should remove only 1 user:

User.findOne({age: 30}).remove(callback);

oh, not as I expected, the code above also remove ALL instead of ONE

So, why findOne().remove() remove ALL instead of ONE? Is that a bug or a feature and why?

Thanks in advance!

P/S: I know findOneAndRemove() would remove one user for me, but in this question I want to understand findOne().remove()

3 Answers
Related