MongoDB $facet
Run several independent sub-pipelines on the same input.
Each named branch receives the same documents and returns its results as an array. Use it when one response needs several coordinated summaries.
Stages are the top-level steps in a pipeline. Each stage receives documents, changes the stream in one specific way, and passes its output to the next stage.
Course use: Exercise 11 and Hard Mode 13.
Example pipeline syntax { $facet: {
byChannel: [{ $group: { _id: "$channel" } }],
byRegion: [{ $group: { _id: "$region" } }]
} }
Continue learning Challenge 17: Run parallel analyses For completed orders, return `byChannel` revenue summaries and the top two `byRegion` summaries in one document. Challenge 20: Assemble an operations dashboard For completed orders, return one document with `regionalRevenue`, `largestOrders`, and `unitsByChannel`. Regional summaries need revenue and order count; largest orders need the top three compact order records; channel summaries need item units. Challenge 21: Build the commerce command report For completed orders, return one document with three arrays. `categoryPerformance` contains the top three categories with `category`, `revenue`, and `units`. `segmentPerformance` contains every customer segment with `segment`, `revenue`, `orderCount`, and `averageOrder`. `topOrder` contains the largest order with `orderId`, `region`, and `total`. Sort every report by revenue or total descending, using its name as the tie-breaker. Official MongoDB $facet documentation Browse all aggregation operators