To solve the problem of mongodb mapreduce traversing values.

  mongodb, question

In the reduce function of mongodb mapreduce, the parameter values is an array that can be traversed by values.forEach.

function(key, values){
 //values is an array
 //val is the element in the array.

However, when values are relatively large, values will be split and stored. forEach in the original Reduce function only traverses the data of the first layer, and cannot traverse all elements. Then how do I traverse all the elements in values?

Mapreduce also has a parameter scope, which can be used to place variables used in js functions. You can temporarily store value data in Mapreduce, so that data can be obtained across a single Reduce function. However, since the values are split, it shows that the data in the values is large. if all the values are combined by force, it is not a good method and the memory will be tight. It is better to optimize the map function and reduce the amount of values data.