Challenge - 5 Problems
Aggregation Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ query_result
intermediate2:00remaining
Output of a simple $group aggregation
Given a collection
sales with documents like { "item": "apple", "quantity": 5 }, what is the output of this aggregation?{ "$group": { "_id": "$item", "total": { "$sum": "$quantity" } } }MongoDB
db.sales.aggregate([{ "$group": { "_id": "$item", "total": { "$sum": "$quantity" } } }])Attempts:
2 left
💡 Hint
Think about grouping by the item field and summing quantities per item.
✗ Incorrect
The $group stage groups documents by the 'item' field and sums the 'quantity' for each group. So each item gets its total quantity.
❓ query_result
intermediate2:00remaining
Effect of $match before $group
What is the output of this aggregation on the
sales collection?[
{ "$match": { "item": "apple" } },
{ "$group": { "_id": "$item", "total": { "$sum": "$quantity" } } }
]MongoDB
db.sales.aggregate([{ "$match": { "item": "apple" } }, { "$group": { "_id": "$item", "total": { "$sum": "$quantity" } } }])Attempts:
2 left
💡 Hint
The $match filters documents before grouping.
✗ Incorrect
Only documents with item 'apple' are included before grouping, so total sums only apple quantities.
📝 Syntax
advanced2:00remaining
Identify the syntax error in aggregation pipeline
Which option contains a syntax error in the MongoDB aggregation pipeline?
MongoDB
db.sales.aggregate([{ "$group": { "_id": "$item", "total": { "$sum": "$quantity" } } }])Attempts:
2 left
💡 Hint
Field names must be strings with $ prefix inside $sum.
✗ Incorrect
Option B uses quantity without quotes and $ prefix, causing syntax error.
❓ optimization
advanced2:00remaining
Optimizing aggregation with $match and $group order
Which pipeline order is more efficient for filtering and grouping a large collection?
Attempts:
2 left
💡 Hint
Filtering early reduces data processed in grouping.
✗ Incorrect
Applying $match first reduces documents before grouping, improving performance.
🧠 Conceptual
expert2:00remaining
Why aggregation operators matter in data analysis
Which statement best explains why aggregation operators like $sum, $avg, and $group are important in MongoDB?
Attempts:
2 left
💡 Hint
Think about how aggregation helps handle data inside the database.
✗ Incorrect
Aggregation operators let you summarize and analyze data inside MongoDB, making queries faster and simpler.