These functions are available for use in the $group stage, accumulators are operators that maintain their state (e.g. totals, maximums, minimums, and related data) as information progress through the pipeline.
When used as accumulators in the $group stage, these operators 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.
Access via $
Returns the result of a user-defined accumulator function
Returns an array of unique expression values for each group. Order of the array elements is undefined
Returns an average of numerical values. Ignores non-numeric values
Some operators that are available as accumulators for the $group stage are also available for use in other. When used in these other stages, these operators do not maintain their state and can take as input either a single argument or multiple arguments.
Access via $
Returns array of unique pushed values
Calculates the average of a number property or expression in the group.
Performs a count of a grouped documents or, if the property is an array, a count of the number of elements.
Returns the first value from the group. The result depends on the sort field(s)
Returns the last value from the group. The result depends on the sort field(s)
Combines multiple documents into a single document
Returns the smallest value from the group.
Returns the largest value from the group
Returns the array of pushed values
Calculates the sum of a number property or expression in the group