我有一个非常大的MongoDB数据库,需要通过运行Map Reduce查询来提取统计数据。
现在的问题是,我需要缩小查询范围,例如使用status:'drafted"代替使用整个集合。
以下是我的Map/Reduce代码(我正在使用Codeigniter):
我尝试遵循此查询中的最后一步,但无法获得结果,因此我认为我的语法添加错误:http://cookbook.mongodb.org/patterns/unique_items_map_reduce/。
现在的问题是,我需要缩小查询范围,例如使用status:'drafted"代替使用整个集合。
以下是我的Map/Reduce代码(我正在使用Codeigniter):
我尝试遵循此查询中的最后一步,但无法获得结果,因此我认为我的语法添加错误:http://cookbook.mongodb.org/patterns/unique_items_map_reduce/。
$map = new MongoCode ("function() {
day = Date.UTC(this.created_at.getFullYear(), this.created_at.getMonth(), this.created_at.getDate());
emit ({day: day, _id: this._id}, {created_at: this.created_at, count: 1});
}");
$reduce = new MongoCode ("function( key , values ) {
var count = 0;
values.forEach (function(v) {
count += v['count'];
});
return {count: count};
}");
$outer = $this->cimongo->command (array (
"mapreduce" => "documents",
"map" => $map,
"reduce" => $reduce,
"out" => "stats_results"
));
$map = new MongoCode ("function() {
emit(this['_id']['day'], {count: 1});
}");
$reduce = new MongoCode ("function( key , values ) {
var count = 0;
values.forEach (function(v) {
count += v['count'];
});
return {count: count};
}");
$outer = $this->cimongo->command (array (
"mapreduce" => "stats_results",
"map" => $map,
"reduce" => $reduce,
"out" => "stats_results_unique"
));