Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

orFail() does not work with findOneAndRemove() #9381

Closed
iFork opened this issue Sep 3, 2020 · 1 comment
Closed

orFail() does not work with findOneAndRemove() #9381

iFork opened this issue Sep 3, 2020 · 1 comment
Labels
confirmed-bug We've confirmed this is a bug in Mongoose and will fix it.
Milestone

Comments

@iFork
Copy link

iFork commented Sep 3, 2020

Do you want to request a feature or report a bug?
Bug
What is the current behavior?
When orFail() is chained on a findOneAndRemove() or findByIdAndRemove() query, no error is thrown when no document is found. Instead the query result is null as if orFail() was not used.

If the current behavior is a bug, please provide the steps to reproduce.

Person.findByIdAndRemove(id)
    .orFail()
    .then(deletedPerson => {
        if (deletedPerson) {
            console.log("deleted:", deletedPerson);
        } else {
            console.log("nothing to delete"); 
            // this block should not be reachable if orFail() worked
       }
    })
    .catch(err => console.log("error:", err));

What is the expected behavior?
See above.
What are the versions of Node.js, Mongoose and MongoDB you are using? Note that "latest" is not a version.
Node: 14.4.0
Mongoose: 5.10.3
MongoDB: 3.6.1

See also #7280 (mentions also this same issue), #8030

@vkarpov15 vkarpov15 added this to the 5.10.4 milestone Sep 6, 2020
@vkarpov15
Copy link
Collaborator

Thanks for pointing this out, fix will be in 5.10.4.

@vkarpov15 vkarpov15 added the confirmed-bug We've confirmed this is a bug in Mongoose and will fix it. label Sep 6, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
confirmed-bug We've confirmed this is a bug in Mongoose and will fix it.
Projects
None yet
Development

No branches or pull requests

2 participants