Suggest an editImprove this articleRefine the answer for “What does the $group stage do?”. Your changes go to moderation before they’re published.Approval requiredContentWhat you’re changing🇺🇸EN🇺🇦UAPreviewTitle (EN)Short answer (EN)The `$group` stage groups documents by one or several fields and lets you compute aggregates - sum, count, max, min, average, and so on; it's the analog of `GROUP BY` in SQL, where the `_id` field is always the grouping key. **Key point:** the result is a new set of documents, one per group, and everything outside of `_id` must be an aggregate operation (`$sum`, `$avg`, `$max`, `$min`, `$push`, etc.).Shown above the full answer for quick recall.Answer (EN)ImageThe `$group` stage **groups documents by one or several fields** and lets you compute aggregates - sum, count, max, min, average, and so on. It's the analog of `GROUP BY` in SQL. ### What happens inside - documents get combined by a key (the field specified in `_id`) - aggregate values are computed for each group (`$sum`, `$avg`, `$max`, `$min`, `$push`, and others) - the result is a set of **new documents**, one per group ### Example ```js { $group: { _id: "$status", total: { $sum: 1 } } } ``` Result: the count of documents in each `status` group. ### The key point In `$group`, the `_id` field is the **grouping key**. Everything that isn't `_id` has to be an aggregate operation. ### Summary `$group` is the stage that collects documents into groups and computes final values for each group, producing aggregated data.For the reviewerNote to the moderator (optional)Visible only to the moderator. Helps review go faster.