Challenge 1: Translate a GROUP BY Query — Possible Solution ==================================================================== db.products.aggregate([ { $group: { _id: "$category", product_count: { $sum: 1 }, avg_price: { $avg: "$price" } } }, { $sort: { product_count: -1 } } ]) WHY THIS WORKS AS AN ANSWER ------------------------------ The SQL query has no WHERE clause, so the pipeline needs no $match stage at all — every product participates in the grouping. $group's _id holds the grouping key ("$category"), the same role category plays after GROUP BY in the SQL version. COUNT(*) becomes { $sum: 1 } — adding 1 for every document in the group, since there's no specific field being summed, just documents being counted. AVG(price) becomes { $avg: "$price" } directly, MongoDB's accumulator mirroring SQL's aggregate function almost exactly. $sort then orders by product_count descending (-1), matching ORDER BY product_count DESC. Note that $sort refers to product_count, the NEW field name created by $group — not any field that existed on the original product documents.