Challenge 2: Build a $facet Dashboard Query — Possible Solution ==================================================================== db.reviews.aggregate([ { $facet: { averageRating: [ { $group: { _id: null, avg: { $avg: "$rating" } } } ], recentReviews: [ { $sort: { createdAt: -1 } }, { $limit: 3 } ] } } ]) WHY THIS WORKS AS AN ANSWER ------------------------------ Both sub-pipelines start from the SAME input — every document in reviews — because $facet feeds its input to each named sub-pipeline independently, rather than passing one sub-pipeline's output into the next (unlike every stage seen before this chapter). averageRating uses $group with _id: null, collapsing every review into a single result document holding one computed average — the same "group everything into one bucket" pattern used for a grand total. recentReviews is a completely different kind of operation — sorting individual documents and taking the top 3 — with no grouping or computation at all. That's the point of $facet: these two sub-pipelines don't need to resemble each other in shape or purpose, only share the same starting input. The result is one document: { averageRating: [ { _id: null, avg: 4.2 } ], recentReviews: [ {...}, {...}, {...} ] } — both answers back in a single round trip instead of two separate queries.