求解mongodb mapreduce 遍历values的问题。
ringa_lee
ringa_lee 2017-04-28 09:06:06
0
1
623

在mongodb mapreduce的reduce函数中,参数values是一个数组,可以用values.forEach进行遍历。

function(key, values){
    //values 是一个数组
    values.forEach(function(val){
        //val即为数组里的元素
    });
}

但是values比较大时,values会被会被拆分存储,在原本Reduce函数中的forEach只遍历了第一层的数据,无法遍历所有的元素。那请问如何遍历values里的所有元素?

ringa_lee
ringa_lee

ringa_lee

reply all(1)
伊谢尔伦

There is also a parameter scope in mapreduce, which can place variables used in js functions. You can temporarily store value data in it, so that you can obtain data across a single reduce function. However, since the values ​​are split, it means that the amount of data in the values ​​is large. If you just forcibly combine all the values, it is not a good idea, and the memory will be tight. It is better to optimize the map function and reduce the amount of values ​​​​data.

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template