Introduction
A pipeline helps process data step-by-step, like an assembly line, making it easy to transform and analyze data in order.
db.collection.aggregate([
{ stage1 },
{ stage2 },
...
])db.sales.aggregate([
{ $match: { status: "A" } },
{ $group: { _id: "$item", total: { $sum: "$amount" } } }
])db.users.aggregate([
{ $sort: { age: -1 } },
{ $limit: 5 }
])db.orders.aggregate([
{ $match: { status: "shipped" } },
{ $group: { _id: "$customer", totalSpent: { $sum: "$price" } } },
{ $sort: { totalSpent: -1 } }
])[{ $match: { age: { $gte: 18 } } }, { $group: { _id: '$city', count: { $sum: 1 } } }], what does the output represent?[{ $match: { score: { $gt: 50 } } }, { $project: { score: 1, name: 1 } }, { $match: { name: 'Alice' } }]Pass the test and this pattern moves unknown