MapReduce is actually batch processing of data, every 100 times reduce processing, so to reduce the data if it is 101, it will be divided into 2 times.
The problem is that in reduce if you initialize var count = 0; in the loop count + +, the last output is 1???
The way to avoid this is to put the data in the returned value, which is reused when the loop enters reduce. In the loop count + = Value.count will be able to add before all 100!!!
And if there is only one piece of data, then it will not enter reduce and will return directly.
Here is a concrete example:
String map = @ " function () { var view = this; Emit (View.activity, {pv:1}); }" ; = @ " function (key, values) { var result = {pv:0}; Values.foreach (function (value) { RESULT.PV + = value.pv; }); return result; }" ; = @ " function (key, value) { return value; }";
Plan to use MongoDB MapReduce before you must know!!!