私は統計情報を抽出する必要があるむしろ大きなMongoDBを取得しました。私はMap Reduceクエリを実行して購入します。MongoDBマップでクエリを減らす
問題は今、私は例の状態で使用するクエリ狭くする必要があるということです。代わりに、コレクション全体を使っての「」起草を
これは私の地図/コードを(私は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"
));
あなたは " '起草' 使用状況" とは何を意味するのですか?テーブル全体をマッピングしないようにしたいのですか、それともそのステータスのキーだけを放ちますか?あなたが望むのは、状況フィールドに基づいて条件付きで結果を出すことだと思います。 – evnu