Trying out 2.4 before moving it to production, I've run across an issue with map-reduce.
The output of my MR replaces a collection, if I run it with jsmode:false, the collection is empty. With jsmode:true, output is normal.
Using 2.2, jsmode:false works fine.
Here is my map reduce command.
db.runCommand({ mapreduce: "agents",
map : function Map() {
var data = { count: 1, systems : {}};
data.systems[this.sys] = 1;
emit(this.email, data);
},
reduce : function Reduce(key, values) {
var reduced = {count: 0, systems: {}}; // initialize a doc (same format as emitted value)
values.forEach(function(val) {
for(var key in val.systems) {
if (reduced.systems[key]) {
reduced.systems[key] += val.systems[key];
} else {
reduced.systems[key] = val.systems[key];
}
}
reduced.count += val.count;
});
return reduced;
},
finalize : function Finalize(key, reduced) {
/*
// Make final updates or calculations
reduced.avgAge = reduced.age / reduced.count;
*/
reduced.syscount = 0;
reduced.maxcount = 0;
for(var sys in reduced.systems)
{
reduced.syscount++;
if (reduced.systems[sys] > reduced.maxcount) {
reduced.maxcount = reduced.systems[sys];
}
}
return reduced;
},
query : { "sys" : { "$ne" : "stakeholders" }, "status" : "Active" },
out : { replace: "jwc_test" },
jsMode : true
});