Aggregation Commands Comparison
On this page
Note
Aggregation Pipeline as Alternative to Map-Reduce
Starting in MongoDB 5.0, map-reduce is deprecated:
Instead of map-reduce, you should use an aggregation pipeline. Aggregation pipelines provide better performance and usability than map-reduce.
You can rewrite map-reduce operations using aggregation pipeline stages, such as
$group
,$merge
, and others.For map-reduce operations that require custom functionality, you can use the
$accumulator
and$function
aggregation operators. You can use those operators to define custom aggregation expressions in JavaScript.
For examples of aggregation pipeline alternatives to map-reduce, see:
Aggregation Commands Comparison Table
The following table provides a brief overview of the features of the MongoDB aggregation commands.
Description | Designed with specific goals of improving performance and usability for aggregation tasks. Uses a "pipeline" approach where objects are transformed as they
pass through a series of pipeline operators such as
See Aggregation Operators for more information on the pipeline operators. | Implements the Map-Reduce aggregation for processing large data sets. |
Key Features | Pipeline operators can be repeated as needed. Pipeline operators need not produce one output document for every input document. Can also generate new documents or filter out documents. Using the | In addition to grouping operations, can perform complex aggregation tasks as well as perform incremental aggregation on continuously growing datasets. |
Flexibility | You can define custom aggregation expressions with You can also add computed fields, create new virtual sub-objects, and
extract sub-fields into the top-level of results by using the
See | Custom See |
Output Results | Returns results as a cursor. If the pipeline includes the
With With | Returns results in various options (inline, new collection, merge,
replace, reduce). See mapReduce for details on the
output options. |
Sharding | Supports non-sharded and sharded input collections.
| Supports non-sharded and sharded input collections. |
More Information |