我有一个相当大的 MongoDB,我需要从中提取统计信息,我这样做是为了运行 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"
));