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() now throws when matchedCount === 0 #12809

Merged
merged 2 commits into from
Dec 16, 2022
Merged

Conversation

IslandRhythms
Copy link
Collaborator

No description provided.

Copy link
Collaborator

@AbdelrahmanHafez AbdelrahmanHafez left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should add a couple of test cases:
1- That throws an error on matchedCount: 0.
2- One that passes on matchedCount: 1, modifiedCount: 0.

Other than that, LGTM! 👍

const res = await Person.updateOne({ _id: doc._id }, { name: 'Darth Vader' }).orFail();
assert.equal(res.matchedCount, 1);
await assert.rejects(async() => {
await Person.updateOne({ name: 'Anakin' }, { name: 'The Chosen One' }).orFail();
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You were the chosen one! 🤣

@vkarpov15 vkarpov15 merged commit 37d0179 into 7.0 Dec 16, 2022
@vkarpov15 vkarpov15 added this to the 7.0 milestone Dec 16, 2022
@hasezoey hasezoey deleted the IslandRhythms/gh-11620 branch May 19, 2023 16:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Make orFail() throw on updateOne() and updateMany() if matchedCount === 0, not modifiedCount === 0
3 participants