Aggregation options
Usually, the use case for aggregation is grouping together attribute values from multiple documents or returning a single result after processing a set of documents.
We can also use the aggregation framework to track how data changes over time in a collection.
One example would be calculating the average value for an attribute across all documents of a collection.
We can use either one or more aggregation pipelines, forming a Directed Acyclic Graph (DAG) for the calculations or a single-purpose aggregation method for simple one-off calculations.
In earlier versions, we could also use Map Reduce, but as of MongoDB 5.0, the Map-reduce framework has been deprecated and, as such, should not be used for new development.
Existing map reduce code can be rewritten using an aggregation pipeline in multiple stages. The $accumulator
and $function
aggregator operators that were introduced in MongoDB 4.4 can be used to define custom aggregation expressions using...