Question 24 / 50
Good to KnowMediumScenarioAggregation
A dashboard needs completed-order count, revenue, and top 5 products from the same day's orders. Would you use $facet or three aggregations?
Think about it first.
Short answer
If all three need the same $match, $facet can run them in one round trip over one filtered stream. If they need different indexes or you want simpler failure modes, three aggregations are fine — and often clearer. Do not $facet over the whole collection just to save a network hop.
Why?
$facet still does the work of each sub-pipeline. It helps when the expensive part is the shared $match. It hurts when one facet is a huge unwind the others do not need. For a dashboard, readability and independent caching sometimes beat a clever single pipeline.
How did you do?
Learn
Cheat Sheet