Pipeline Practice

Build value bands

`$bucket` divides a continuous value into explicit ranges. Each lower boundary is inclusive; the next boundary closes the range.

Bucket orders by total into 0–99, 100–199, and 200–999. Return count and revenue for each band.

Expected result: Three bucket documents ordered by lower boundary.

Example pipeline syntax

[
  { $bucket: { groupBy: "$total", boundaries: [0, 1000], output: { count: { $sum: 1 } } } }
]