Challenge - 5 Problems
MongoDB Shell 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
Assume the collection has:
users with documents containing age and name, what is the output of this query?db.users.find({ age: { $gt: 30 } }).toArray()Assume the collection has:
{ name: 'Alice', age: 25 }{ name: 'Bob', age: 35 }{ name: 'Carol', age: 40 }MongoDB
db.users.find({ age: { $gt: 30 } }).toArray()Attempts:
2 left
💡 Hint
Look for documents where age is greater than 30.
✗ Incorrect
The query finds all users with age greater than 30, so Bob and Carol match.
📝 Syntax
intermediate1:30remaining
Identify the syntax error in the query
Which option contains a syntax error when trying to find documents where
status is 'active'?MongoDB
db.orders.find({ status: 'active' })Attempts:
2 left
💡 Hint
Check the use of colon and equal sign in object syntax.
✗ Incorrect
In MongoDB queries, the filter object uses colon ':' to assign values, not '='.
❓ optimization
advanced2:00remaining
Optimize query to return only specific fields
You want to find all documents in
products collection but only return the name and price fields. Which query is correct?Attempts:
2 left
💡 Hint
Use projection to include fields by setting them to 1.
✗ Incorrect
Projection with 1 includes fields; 0 excludes. Mixing 1 and 0 (except _id) is invalid.
🧠 Conceptual
advanced2:30remaining
Understanding the effect of update operators
What will be the result of this update operation?
Assuming the document before update is:
db.inventory.updateOne({ item: 'book' }, { $set: { qty: 50 }, $inc: { sold: 5 } })Assuming the document before update is:
{ item: 'book', qty: 20, sold: 10 }Attempts:
2 left
💡 Hint
Remember $set replaces the field value; $inc adds to the existing value.
✗ Incorrect
$set changes qty to 50; $inc adds 5 to sold (10 + 5 = 15).
🔧 Debug
expert3:00remaining
Identify the cause of the error in aggregation pipeline
This aggregation pipeline causes an error:
What is the most likely cause of the error?
db.sales.aggregate([ { $match: { status: 'A' } }, { $group: { _id: '$cust_id', total: { $sum: '$amount' } } }, { $sort: { total: -1 } } ])What is the most likely cause of the error?
Attempts:
2 left
💡 Hint
Check data types for aggregation operators.
✗ Incorrect
$sum requires numeric values; if 'amount' has strings, aggregation fails.