Trying to run a map reduce on a mongodb collection. Using iReport to design/test the report.
The problem is:
I specify "findQuery" to filter out the rows/documents I want to run map reduce on. Then I use mapReduce to specify map, reduce and out.
But the map reduce is run on all rows/documents in the collection, and then "findQuery" is applied on result of map reduce.
Following is the complete query that I have written in the edit query dialog box in iReport.
{
collectionName: "packages",
findQuery: {"cs.ss": "RTO"},
sort: {'cn': 1},
mapReduce: {
'map': 'function () {
var p1 = 0; var p2 = 0; var p3 = 0; var p4 = 0;
var diff = Math.ceil((ISODate().getTime()+330*60*1000-this.pd.getTime())/(1000*60*60*24));
if (diff == 1){
p1 = 1;
}else{
if (diff == 2){
p2 = 1;
}else{
if (diff == 3){
p3 = 1;
}else{
p4 = 1;
}
}
}
var cn = String(this.cn);
emit({cn: cn}, {p1: p1, p2: p2, p3: p3, p4: p4});
}',
'reduce': 'function (key, values){
var result = {p1: 0, p2: 0, p3: 0, p4: 0};
values.forEach(function (v){
result.p1 += parseInt(v.p1);
result.p2 += parseInt(v.p2);
result.p3 += parseInt(v.p3);
result.p4 += parseInt(v.p4);
});
return result;
}',
'out': 'cn_wise_pendency',
},
}
0 Answers:
No answers yet