Skip to content

Conversation

@tkaye407
Copy link
Contributor

Not sure if this is a big deal/wrong, but the findOne() method returns null as opposed to undefined when there are no matching documents. We can discuss if this is not the right behaviour.

@tkaye407 tkaye407 requested a review from adamchel February 16, 2019 00:00
@coveralls
Copy link

coveralls commented Feb 16, 2019

Coverage Status

Coverage increased (+0.1%) to 77.836% when pulling f88a999 on tkaye407:findOne into 563bc7f on mongodb:master.

Copy link
Contributor

@adamchel adamchel left a comment

Choose a reason for hiding this comment

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

Looks good to me, though I'm of the opinion we should be using undefined everywhere, since mixing undefined and null can get very confusing for users. Let's have a slack discussion about why the server returns null, and make a decision based on that. If we do end up going with null, we need to make sure we update the Promise types returned by the findOne methods.

Copy link
Contributor Author

@tkaye407 tkaye407 left a comment

Choose a reason for hiding this comment

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

Now findOne() will return undefined

return undefined;
}

const obj = EJSON.parse(response.body!, { strict: false });
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is what I added, let me know if this is too sketchy

Copy link
Contributor

Choose a reason for hiding this comment

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

This is very sketchy, and I don't think it's a check we should be making for every request.

Would it be better to do the following

if (obj === null) {
    return undefined;
}

after the EJSON.parse call?

@tkaye407 tkaye407 merged commit e9eb9f1 into mongodb:master Feb 21, 2019
@tkaye407 tkaye407 deleted the findOne branch March 18, 2019 13:54
@tkaye407 tkaye407 restored the findOne branch March 18, 2019 13:54
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.

3 participants