-
-
Notifications
You must be signed in to change notification settings - Fork 3.9k
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
Make orFail()
throw on updateOne()
and updateMany()
if matchedCount === 0
, not modifiedCount === 0
#11620
Comments
From the docs // Throws if no document was updated
await Model.updateOne({ foo: 'bar' }, { name: 'test' }).orFail(); I'll mark this as a docs issue as it could be more clear that the update operation needs to update something to not throw. |
We made a note about this in the docs. However, we should consider changing this behavior in v7. 2 reasons why:
|
vkarpov15
added a commit
that referenced
this issue
May 6, 2022
…cument updated, not if no document found Re: #11620
I think this option totally makes sense, hence my original feedback about the method. Thanks a lot for taking care of it! |
orFail()
throw on updateOne()
and updateMany()
if matchedCount === 0
, not modifiedCount === 0
vkarpov15
added a commit
that referenced
this issue
Dec 16, 2022
`orFail()` now throws when `matchedCount === 0`
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Do you want to request a feature or report a bug?
bug
What is the current behavior?
orFail helper method will throw error on update if document is matched but not changed due to the query nature
No document found for query
This is misleading to figure it out, since document was indeed found.
If the current behavior is a bug, please provide the steps to reproduce.
This would throw an error if called on a User object which already has {metrics:{invites:0}};
What is the expected behavior?
I would expect that updateOne statement won't throw error in case matchedCount === 1 in this case, because the query is made in such a way so that if called multiple times will do nothing once user has the same value set.
What are the versions of Node.js, Mongoose and MongoDB you are using? Note that "latest" is not a version.
NodeJS V16
"mongoose": "^6.2.8"
The text was updated successfully, but these errors were encountered: