findOne()
Reference group: Collection CRUD methods
What it does
Returns one matching document or null.
Syntax
db.collection.findOne(filter, projection)
Use case
Fetch a record by a unique key.
Important notes
Without sort, the selected match is not a stable business ordering.
findOne(): practical example
db.users.findOne({ email: "asha@example.com" }, { passwordHash: 0 })💡 Explanation
Returns one matching document or null.
When to use it
Fetch a record by a unique key.
Caution
Without sort, the selected match is not a stable business ordering.
Key Takeaways
- Returns one matching document or null.
- Typical use: Fetch a record by a unique key.