Build the commerce command report
Hard Mode is about simultaneous grain control. Each `$facet` branch receives the same completed orders, but one must become product-category lines, one must remain customer-level orders, and one must isolate a single order. A correct answer depends on never mixing those grains.
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.
Expected result: Exactly one document with three correctly ordered report arrays and at least 18 stage operations across the pipeline and facet branches.
Example pipeline syntax
[
{ $match: { status: "completed" } },
{ $facet: {
categoryPerformance: [],
segmentPerformance: [],
topOrder: []
} }
]