- 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.
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 $group stage only. |
$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 $group stage only. |
$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 $group stage only. |
$addToSet | Returns an array of unique expression values for each group. Order of the array elements is undefined. Available in $group stage only. |
$stdDevPop | Returns the population standard deviation of the input values. |
$stdDevSamp | Returns the sample standard deviation of the input values. |
Thank you for your feedback!
We're sorry! You can Report a Problem to help us improve this page.