Complete the code to start an aggregation pipeline with a match stage filtering documents where age is greater than 25.
db.users.aggregate([ { $[1]: { age: { $gt: 25 } } } ])The $match stage filters documents based on the given condition. Here, it selects users older than 25.
Complete the code to sort the documents by score in descending order after filtering.
db.users.aggregate([ { $match: { active: true } }, { $[1]: { score: -1 } } ])The $sort stage orders documents. Using { score: -1 } sorts by score descending.
Fix the error in the pipeline by placing the $project stage correctly to include only name and score fields.
db.users.aggregate([ { $[1]: { score: { $gt: 50 } } }, { $project: { name: 1, score: 1 } } ])The $match stage should come before $project to filter documents before selecting fields.
Fill both blanks to correctly filter active users and then group them by city counting the number of users per city.
db.users.aggregate([ { $[1]: { active: true } }, { $[2]: { _id: "$city", count: { $sum: 1 } } } ])First, $match filters active users. Then, $group groups by city and counts users.
Fill all three blanks to filter users older than 30, sort by age ascending, and project only name and age fields.
db.users.aggregate([ { $[1]: { age: { $gt: 30 } } }, { $[2]: { age: 1 } }, { $[3]: { name: 1, age: 1, _id: 0 } } ])The pipeline first filters with $match, then sorts with $sort, and finally selects fields with $project.