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

findAndModify now returns T | null instead of T | undefined #397

Merged
merged 4 commits into from Jun 8, 2023

Conversation

AsPulse
Copy link
Contributor

@AsPulse AsPulse commented Jun 8, 2023

According to the Official document of mongoDB, findAndModify returns the document or null.

I test this problem by below code:

const collection = /*...*/;
const result = await collection.findAndModify(
  {
    name: 'abc',
  },
  {
    update: {
      $set: {
        'someField': 12345,
      },
    },
    new: false,
  },
);

I've confirmed that the result is a pre-updated document if the document matches { name: 'abc' } found, if not, the result is certainly null.

Maybe, the return type should be Promise<T | null>.

Last but not least, I apologize if there are any mistakes in my English writing. I am just Japanese student learning English ;)

@AsPulse AsPulse requested a review from erfanium as a code owner June 8, 2023 07:41
@AsPulse AsPulse force-pushed the fix/return-type-of-findAndModify branch from 3089da0 to b08139b Compare June 8, 2023 08:00
@AsPulse AsPulse force-pushed the fix/return-type-of-findAndModify branch from b08139b to 11b4489 Compare June 8, 2023 08:01
@lucsoft lucsoft merged commit 6e27e38 into denodrivers:main Jun 8, 2023
5 checks passed
@lucsoft
Copy link
Collaborator

lucsoft commented Jun 8, 2023

Looks great thanks very much for the PR!

@AsPulse AsPulse deleted the fix/return-type-of-findAndModify branch June 10, 2023 04:29
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.

None yet

2 participants