March 2019
Intermediate to advanced
394 pages
11h 4m
English
MapReduce operations will place several short-lived locks that should not affect operations. However, at the end of the reduce phase, if we output the data to an existing collection, then output actions such as merge, reduce, and replace will take an exclusive global write lock for the whole server, blocking all other writes to the db instance. If we want to avoid this, then we should invoke mapReduce in the following way:
> db.collection.mapReduce( mapper, reducer, { out: { merge/reduce: bookOrders, nonAtomic: true } })
We can apply nonAtomic only to merge or reduce actions. replace will just replace the contents of documents in bookOrders, which will not take much time anyway.
With the merge action, the new result ...
Read now
Unlock full access