$mapFunc = <<<EOT
function() {
if (!this.summary) {
return;
}
var summary = this.summary;
if (summary.type || summary.sum) {
var index = summary.type + '-' + summary.business;
var data = {
type: summary.type,
business: summary.business,
sum: summary.sum
};
emit(index, data);
}
}
EOT;
$map = new MongoCode($mapFunc);
$reduceFunc = <<<EOT
function(k, list) {
var result = {type:0, business:0, sum: 0};
for (var b in list) {
var item = list[b];
result.type = item.type;
result.business = item.business;
result.sum += item.sum;
}
return result;
}
EOT;
$reduce = new MongoCode($reduceFunc);
$params = array(
"mapreduce" => 'logs',
"map" => $map,
"reduce" => $reduce,
"query" => null,
"out" => '_ex'
);
$mongo = $this->Log->getDataSource();
$results = $mongo->mapReduce($params);
比如我上面的代码是对logs集合进行统计,还有一个extend_logs集合,字段都是一样的,也需要如上统计方法,用mongodb的mapreduce方法统计数据可以同时对两个表进行相应的操作么?