Challenge - 5 Problems
MongoDB Query Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ query_result
intermediate2:00remaining
Find documents with a specific field value
Given a collection
users with documents containing age and name, which query returns all users aged 30?MongoDB
db.users.find({ age: 30 })Attempts:
2 left
💡 Hint
Look for the query that matches the exact age value.
✗ Incorrect
The query
{ age: 30 } matches documents where the age field is exactly 30.❓ query_result
intermediate2:00remaining
Using $and operator in queries
Which query returns users who are aged 25 and have the name 'Alice'?
MongoDB
db.users.find({ $and: [ { age: 25 }, { name: 'Alice' } ] })Attempts:
2 left
💡 Hint
The $and operator requires all conditions to be true.
✗ Incorrect
The $and operator matches documents where both conditions are true: age is 25 and name is 'Alice'.
📝 Syntax
advanced2:00remaining
Identify the syntax error in this MongoDB query
Which option contains a syntax error in the MongoDB query to find users older than 20?
MongoDB
db.users.find({ age: { $gt: 20 } })Attempts:
2 left
💡 Hint
MongoDB operators start with a $ sign.
✗ Incorrect
Option C uses 'gt' without the $ prefix, which is invalid syntax in MongoDB queries.
❓ optimization
advanced2:00remaining
Choose the most efficient query for indexed fields
Assuming
age is indexed, which query is most efficient to find users aged between 20 and 30?Attempts:
2 left
💡 Hint
Use range queries with $gte and $lte for efficient index use.
✗ Incorrect
Option B uses a single range query that MongoDB can optimize with the index on age.
🧠 Conceptual
expert2:00remaining
Why query patterns affect database performance
Which statement best explains why using proper query patterns matters in MongoDB?
Attempts:
2 left
💡 Hint
Think about how indexes and query structure affect speed.
✗ Incorrect
Efficient query patterns help MongoDB use indexes to scan less data, improving performance.