地图代码:
$map = new MongoCode("function(){
emit(333,this);
}");
减少代码:
$reduce = new MongoCode("function(key, values) {
r=0;
for(var idx=0;idx<values.length;idx++){
r+=1;
}
return r;
}");
运行代码:
$result = $db->command(array(
"mapreduce" => "gameLog",
"map" => $map,
"reduce" => $reduce,
"out" => array("replace" => "gameLogResult")
)
);
运行代码返回: Array ( [result] => gameLogResult [timeMillis] => 284 [counts] => Array ( [input] => 18864 [emit] => 18864 [reduce] => 189 [output] => 1 )
[ok] => 1
) map-reduce 的结果是 { "_id" : 333, "value" : 65 },错误我认为结果是 { "_id" : 333, "value" : 18864 } 谁能告诉我为什么会这样,帮助我!