Complete the code to start an aggregation pipeline with the first stage.
db.collection.aggregate([ { [1]: { age: { $gt: 25 } } } ])The $match stage filters documents to pass only those that match the condition. It is usually the first stage in a pipeline.
Complete the code to add a stage that groups documents by 'department' and counts them.
db.collection.aggregate([ { $match: { status: 'active' } }, { [1]: { _id: "$department", count: { $sum: 1 } } } ])The $group stage groups documents by a specified key and can perform accumulations like counting.
Fix the error in the pipeline stage that sorts documents by 'score' descending.
db.collection.aggregate([ { $match: { active: true } }, { [1]: { score: -1 } } ])The $sort stage orders documents by specified fields. Using $sort with { score: -1 } sorts descending by score.
Fill both blanks to project only the 'name' and 'total' fields in the output.
db.collection.aggregate([ { $match: { status: 'complete' } }, { [1]: [2] } ])The $project stage selects which fields to include or exclude. Using { name: 1, total: 1 } includes only those fields.
Fill all three blanks to create a pipeline that filters active users, groups by city counting users, and sorts by count descending.
db.users.aggregate([ { [1]: { active: true } }, { [2]: { _id: "$city", userCount: { $sum: 1 } } }, { [3]: { userCount: -1 } } ])This pipeline first filters active users with $match, then groups them by city counting users with $group, and finally sorts the results by userCount descending with $sort.