Bucket constructor
- required AggregationExpr groupBy,
- required List boundaries,
- dynamic defaultId,
- Map<
String, Accumulator> ? output,
Creates $bucket
aggregation stage
groupBy
- An expression to group documents by. To specify a field path use Field object. Unless$bucket
includes a default specification, each input document must resolve the groupBy field path or expression to a value that falls within one of the ranges specified by the boundaries.boundaries
- An array of values based on thegroupBy
expression that specify the boundaries for each bucket. Each adjacent pair of values acts as the inclusive lower boundary and the exclusive upper boundary for the bucket. You must specify at least two boundaries.
Example:
An array of [ 0, 5, 10 ]
creates two buckets:
-
[0, 5) with inclusive lower bound 0 and exclusive upper bound 5.
-
[5, 10) with inclusive lower bound 5 and exclusive upper bound 10.
-
defaultId
- Optional. A literal that specifies the_id
of an additional bucket that contains all documents whose groupBy expression result does not fall into a bucket specified by boundaries. If unspecified, each input document must resolve the groupBy expression to a value within one of the bucket ranges specified by boundaries or the operation throws an error. The default value must be less than the lowest boundaries value, or greater than or equal to the highest boundaries value. The default value can be of a different type than the entries in boundaries. -
output
- Optional. A document that specifies the fields to include in the output documents in addition to the _id field. To specify the field to include, you must use accumulator expressions.
Implementation
Bucket(
{required AggregationExpr groupBy,
required List boundaries,
defaultId,
Map<String, Accumulator>? output})
: super(
'bucket',
AEObject({
'groupBy': groupBy,
'boundaries': AEList(boundaries),
if (defaultId != null) 'default': defaultId,
if (output != null) 'output': AEObject(output)
}));