- Reference >
- Operators >
- Aggregation Pipeline Operators >
- Group Accumulator Operators
Group Accumulator Operators¶
Changed in version 3.2: Some accumulators are now available in the $project
stage. In previous versions of MongoDB , accumulators are available
only for the $group
stage.
Accumulators, when used in the $group
stage, maintain their
state (e.g. totals, maximums, minimums, and related data) as documents
progress through the pipeline.
When used in the $group
stage, accumulators take as input a
single expression, evaluating the expression once for each input
document, and maintain their stage for the group of documents that
share the same group key.
When used in the $project
stage, the accumulators do not
maintain their state. When used in the $project
stage,
accumulators take as input either a single argument or multiple
arguments.
Note
For details on specific operator, including syntax and examples, click on the specific operator to go to its reference page.
Name | Description |
---|---|
$sum |
Returns a sum of numerical values. Ignores non-numeric values. |
$avg |
Returns an average of numerical values. Ignores non-numeric values. |
$first |
Returns a value from the first document for each group. Order is only defined if the documents are in a defined order. Available in |
$last |
Returns a value from the last document for each group. Order is only defined if the documents are in a defined order. Available in |
$max |
Returns the highest expression value for each group. |
$min |
Returns the lowest expression value for each group. |
$push |
Returns an array of expression values for each group. Available in |
$addToSet |
Returns an array of unique expression values for each group. Order of the array elements is undefined. Available in |
$stdDevPop |
Returns the population standard deviation of the input values. |
$stdDevSamp |
Returns the sample standard deviation of the input values. |