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.