Navigation
This version of the documentation is archived and no longer supported.

Group Accumulator Operators

Accumulators, available only for the $group stage, compute values by combining documents that share the same group key. Accumulators take as input a single expression, evaluating the expression once for each input document, and maintain their state for the group of documents.

Name Description
$sum Returns a sum for each group. Ignores non-numeric values.
$avg Returns an average for each group. 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.
$last Returns a value from the last document for each group. Order is only defined if the documents are in a defined order.
$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.
$addToSet Returns an array of unique expression values for each group. Order of the array elements is undefined.