ADVERTISEMENT
Google AdSense Slot (headerLeaderboard)
Set your Publisher ID in src/config/ads.ts to display live ads.
MongoDB NoSQL Database Tutorial• 7 min read
The Aggregation Pipeline: $match, $group & $project
Process streams of documents through multi-stage aggregation pipelines for reporting, data reshaping, and analytics.
Multi-Stage Document Processing
Documents enter a multi-stage pipeline where each stage transforms the data stream: $match filters rows, $group aggregates sums and averages, and $project reshapes final fields.
3-Stage Aggregation Pipeline
db.orders.aggregate([
// Stage 1: Filter active orders
{ $match: { status: "completed" } },
// Stage 2: Group by customer
{ $group: {
_id: "$customerId",
totalSpent: { $sum: "$total" },
itemCount: { $sum: 1 }
}},
// Stage 3: Sort by highest spenders
{ $sort: { totalSpent: -1 } }
]);ADVERTISEMENT
Google AdSense Slot (inContentBanner)
Set your Publisher ID in src/config/ads.ts to display live ads.
Test Yourself With Exercise
Which aggregation pipeline stage filters documents to allow only those that match specified conditions to proceed to the next stage?