Challenge - 5 Problems
MongoDB findOne Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ query_result
intermediate2:00remaining
Find the first user named 'Alice'
Given a collection
users with documents containing name and age, what will this query return?db.users.findOne({ name: 'Alice' })MongoDB
db.users.findOne({ name: 'Alice' })Attempts:
2 left
💡 Hint
Remember, findOne returns only one document, not multiple.
✗ Incorrect
The findOne method returns the first document matching the query filter. It does not return multiple documents or an array.
📝 Syntax
intermediate2:00remaining
Identify the syntax error in this findOne query
Which option shows the correct syntax for finding a user with age 30 using findOne?
MongoDB
db.users.findOne({ age: 30 })Attempts:
2 left
💡 Hint
The query filter must be an object with key-value pairs.
✗ Incorrect
Option A uses the correct object syntax with key and value. Option A misses braces, A uses invalid comparison operator, D uses string instead of number for age.
❓ query_result
advanced2:00remaining
What does this findOne query return with projection?
Given documents with fields
name, age, and city, what will this query return?db.users.findOne({ name: 'Bob' }, { age: 1, _id: 0 })MongoDB
db.users.findOne({ name: 'Bob' }, { age: 1, _id: 0 })Attempts:
2 left
💡 Hint
Projection controls which fields are included or excluded in the result.
✗ Incorrect
The projection includes age (1) and excludes _id (0), so only age is returned without _id.
🔧 Debug
advanced2:00remaining
Why does this findOne query return null?
Consider this query:
It returns
db.users.findOne({ age: { $gt: 50 } })It returns
null. What is the most likely reason?Attempts:
2 left
💡 Hint
Think about what null means in findOne results.
✗ Incorrect
findOne returns null if no document matches the query. $gt is valid syntax and findOne returns the first match if any.
🧠 Conceptual
expert2:00remaining
Understanding findOne behavior with multiple matches
If multiple documents match the filter in a findOne query, which document is returned?
Attempts:
2 left
💡 Hint
Think about how MongoDB stores documents internally.
✗ Incorrect
findOne returns the first document it finds in the natural order (insertion order) that matches the filter.