From my experiences the reduce function is operatable only on the emitted results.
If the record is not emitted(grouped) then the reduce function make NOTHING
with this record.
in case of max/min calculation this state can not be catch.
Not emitted records are already have it is max/min value as the one is only one
value in interested field but not a result of the reduce function.
the mentioned state is clearly observed when you try to modify the existing field
that come from emit.
for example:
db.test.drop();
db.test.insert({username:"0000001453"});
db.test.insert({username:"0000000018"});
//db.test.insert({username:"0000000018"});//try with and w/o this.
m=function(){
emit({username:this.username}, {firstname:"firstname",lastname:"lastname"});
}
r=function(key,values){
var x=values[0];
x.firstname="smth";//no effect when not emitted
x.lastname ="smth";//no effect when not emitted
return x;
}
db.test.mapReduce(m,r,{out:"results"});
db.results.find();
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment