Starting in MongoDB 5.0, map-reduce is deprecated:
$group
, $merge
, and others.$accumulator
and $function
aggregation operators, available starting in version 4.4. You can use those operators to define custom aggregation expressions in JavaScript.For examples of aggregation pipeline alternatives to map-reduce, see:
The map-reduce operation is composed of many tasks, including reads from the input collection, executions of the map
function, executions of the reduce
function, writes to a temporary collection during processing, and writes to the output collection.
During the operation, map-reduce takes the following locks:
merge
, replace
, reduce
) take a write lock. This write lock is global, and blocks all operations on the mongod
instance.The final write lock during post-processing makes the results appear atomically. However, output actions merge
and reduce
may take minutes to process. For the merge
and reduce
, the nonAtomic
flag is available, which releases the lock between writing each output document. Starting in MongoDB 4.2, explicitly setting nonAtomic:
false
is deprecated. See the db.collection.mapReduce()
reference for more information.