question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Passing undefined to findOne({_id: undefined}) returns the first item in db

See original GitHub issue

As mentioned in the title const user1 = await users.findOne({ _id: undefined }); will return the first item in the db

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
Kylescottwcommented, Dec 1, 2020

We can close the ticket, I did not know the undefined field is ignored. So essentially passing findOne({ _id: undefined }) is the same as findOne().

Thank you for your time.

0reactions
manyuanrongcommented, Nov 30, 2020

@Kylescottw Has your problem been resolved?

Read more comments on GitHub >

github_iconTop Results From Across the Web

.findOne(undefined) returns first item in the database instead ...
I completely disagree. Passing undefined shouldn't cause passing null to sql query. Null and undefined are completely different primitive values ...
Read more >
mongoDB collection.findOne() returns undefined
log() in the function works, but when using it from another file it returns undefined. const db = client.db('TestDatabase'); const collection = ...
Read more >
Mongoose v6.8.1: Model
The id is cast based on the Schema before sending the command. This function triggers the following middleware. findOne(). * Except for how...
Read more >
typeorm/typeorm - Gitter
If entity already exist in the database, then it loads it. but if no existing entity is found in the database it returns...
Read more >
Collections | Meteor API Docs
Finds the first document that matches the selector, as ordered by sort and skip options. Returns undefined if no matching document is found....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found