Pipeline Practice

MongoDB $group

Combine documents that share a key into summary documents.

The `_id` expression defines the group. Every other output field must use an accumulator such as `$sum` or `$avg`.

Stages are the top-level steps in a pipeline. Each stage receives documents, changes the stream in one specific way, and passes its output to the next stage.

Course use: Exercises 07, 08, 11, 12, and Hard Mode 13.

Example pipeline syntax

{ $group: { _id: "$region", revenue: { $sum: "$total" } } }