-
Notifications
You must be signed in to change notification settings - Fork 61
Add findOne() functionality #233
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
Conversation
adamchel
left a comment
There was a problem hiding this 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.
packages/browser/services/mongodb-remote/src/RemoteMongoCollection.ts
Outdated
Show resolved
Hide resolved
packages/browser/services/mongodb-remote/src/internal/RemoteMongoCollectionImpl.ts
Outdated
Show resolved
Hide resolved
packages/core/services/mongodb-remote/src/internal/CoreRemoteMongoCollection.ts
Outdated
Show resolved
Hide resolved
tkaye407
left a comment
There was a problem hiding this 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 }); |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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?
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.