Challenge - 5 Problems
MongoDB Anti-pattern Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ query_result
intermediate2:00remaining
What is the output of this MongoDB query?
Consider a collection users with documents containing
name and age. What will this query return?MongoDB
db.users.find({age: {$gt: 30}}).limit(2)Attempts:
2 left
💡 Hint
Remember that
limit() restricts the number of documents returned.✗ Incorrect
The query filters users with age > 30 and limits the result to 2 documents.
🧠 Conceptual
intermediate2:00remaining
Why is embedding large arrays in documents an anti-pattern?
In MongoDB, what is a major problem with embedding very large arrays inside a single document?
Attempts:
2 left
💡 Hint
Think about MongoDB's maximum document size.
✗ Incorrect
MongoDB documents have a 16MB size limit. Large arrays can exceed this, causing errors.
📝 Syntax
advanced2:00remaining
Which option causes a syntax error in MongoDB aggregation?
Identify the aggregation pipeline stage that will cause a syntax error.
MongoDB
db.orders.aggregate([
{$match: {status: 'shipped'}},
{$group: {_id: '$customerId', total: {$sum: '$amount'}}},
{$sort: {total: -1}}
])Attempts:
2 left
💡 Hint
Check the syntax of the $sum operator argument.
✗ Incorrect
The $sum operator requires a field path starting with '$'. Missing '$' causes syntax error.
❓ optimization
advanced2:00remaining
Which indexing strategy avoids the anti-pattern of slow queries?
Given a collection with frequent queries filtering by
category and sorting by price, which index is best to optimize performance?Attempts:
2 left
💡 Hint
Think about queries that filter and sort on multiple fields.
✗ Incorrect
A compound index on both fields supports filtering and sorting efficiently, avoiding slow queries.
🔧 Debug
expert3:00remaining
Why does this MongoDB update not modify any documents?
Given the collection
products and this update command, why are no documents updated?MongoDB
db.products.updateMany({tags: 'sale'}, {$set: {discount: 10}})Attempts:
2 left
💡 Hint
Consider how MongoDB matches array fields in queries.
✗ Incorrect
Matching a string directly to an array field requires using
$elemMatch or the string itself if exact match is intended. If tags is an array, matching 'sale' as a string may fail if the array contains objects or different types.