option可以是下面几个选项:
{ inline : 1 } – 不会创建collection,结果保存在内存里,只限于结果小于16MB的情况
如果用collection name作option不能与其它option一起使用,其它则可以,如:
merge选项的可能性最大,但是经过实验发现,它总是会根据“_id”更新整个文档,而不是只更新reduce或者finalize出来的对象里有的字段。
比如我一个已经存在的集合A,有10几个字段,没有emps字段,我运行一个MR操作,reduce出来的是{key,emps:[["0132",70],["1443",30]]},想把emps字段添加到现有的集合A上,结果我10几个字段都没有了,就只剩下emps字段了。
本来想在reduce里引用db对象手工update的,但是现在的版本都不让引用db对象了。
现在只能在mapreduce后,执行一个forEach,手工执行update。
请问mapreduce有没有相应的解决方案。
Use
reduce
, it will calculate your existing results and newly calculated results in the result set using the reduce function (reducer) you provided, and save the final result. The most important thing here is to make the intermediate results output by the mapper have the same format as the final results. Such a reducer is used in two places, once in reduce and once in output. If they have the same format, especially the hierarchy, it will be much easier to write. The reducer can be understood as being only responsible for merging multiple results. If the mapper only outputs an intermediate result, it should be directly used as the final result without going through the reducer. In fact, in MongoDB, when a key corresponds to only one mapper output, it is indeed output directly without going through the reducer.http://docs.mongodb.org/manual/reference/method/db.collection.mapReduce/#output-to-a-collection-with-an-action