-
Type: Bug
-
Resolution: Done
-
Priority: Critical - P2
-
None
-
Affects Version/s: 2.0.3
-
Component/s: JavaScript, MapReduce, Querying
-
Environment:Windows Server 2K8R2 x64
-
ALL
Running MapReduce with a constant key causes null to always be emitted. This makes any scenario where you need to perform global aggregation on the server impossible. While the repro code below is trivial, our actual production code performs much more sophisticated analysis logic on objects.
The following repro code below will assert in the reduce function:
db.items.mapReduce(function () {
emit("foo",
);
}, function (key, values) {
var sum = 0;
values.forEach(function (value)
emit(key, { a: sum });
}, { out: "foo_out" });
"assertion" : "invoke failed: JS Error: TypeError: value has no properties nofile_b:2",
"assertionCode" : 9004,
"errmsg" : "db assertion failure",
"ok" : 0
Note that just a simple change in the id causes the failure to go away (this is not functionally equivalent, nor is it a workaround, but it illustrates the bug):
db.items.mapReduce(function () {
emit(this._id, { a: 1 });
}, function (key, values) {
var sum = 0;
values.forEach(function (value) { sum += value.a; }
);
emit(key,
);
},
);
"result" : "foo",
"timeMillis" : 7951,
"counts" :
,
"ok" : 1,