0
0
MongoDBquery~10 mins

Why the aggregation pipeline is needed in MongoDB - Test Your Understanding

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to start an aggregation pipeline on the 'orders' collection.

MongoDB
db.orders.[1]([{ $match: { status: 'shipped' } }])
Drag options to blanks, or click blank then click option'
Ainsert
Bfind
Cupdate
Daggregate
Attempts:
3 left
💡 Hint
Common Mistakes
Using find() instead of aggregate() for complex data processing.
Trying to use insert() or update() which modify data, not process it.
2fill in blank
medium

Complete the code to filter documents where 'age' is greater than 25 in the aggregation pipeline.

MongoDB
db.users.aggregate([{ $match: { age: { [1]: 25 } } }])
Drag options to blanks, or click blank then click option'
A$lt
B$eq
C$gt
D$ne
Attempts:
3 left
💡 Hint
Common Mistakes
Using $lt which means less than, opposite of what is needed.
Using $eq which means equal, not greater than.
3fill in blank
hard

Fix the error in the aggregation stage that groups documents by 'category' and counts them.

MongoDB
db.products.aggregate([{ $group: { _id: '$category', count: { [1]: 1 } } }])
Drag options to blanks, or click blank then click option'
A$sum
B$avg
C$max
D$min
Attempts:
3 left
💡 Hint
Common Mistakes
Using $avg which calculates average, not count.
Using $max or $min which find max or min values, not counts.
4fill in blank
hard

Fill both blanks to project only the 'name' and 'price' fields in the aggregation pipeline.

MongoDB
db.items.aggregate([{ $project: { [1]: 1, [2]: 1, _id: 0 } }])
Drag options to blanks, or click blank then click option'
Aname
Bprice
Ccategory
Dquantity
Attempts:
3 left
💡 Hint
Common Mistakes
Including fields not needed like 'category' or 'quantity'.
Forgetting to exclude _id if not wanted.
5fill in blank
hard

Fill all three blanks to filter documents with 'score' greater than 80, then sort by 'score' descending, and limit to 5 results.

MongoDB
db.scores.aggregate([ { $match: { score: { [1]: 80 } } }, { $sort: { score: [2] } }, { $limit: [3] } ])
Drag options to blanks, or click blank then click option'
A$gt
B-1
C5
D1
Attempts:
3 left
💡 Hint
Common Mistakes
Using $lt instead of $gt for filtering.
Sorting ascending (1) instead of descending (-1).
Setting limit to a wrong number.