最初の質問については、はい、集計について説明できます。
db.collection.runCommand("aggregate", {pipeline: YOUR_PIPELINE, explain: true})
2 番目の場合、範囲クエリを最適化するために作成するインデックスは、パイプラインの最初に発生する場合、集計パイプラインの$matchステージにも適用されます。したがって、インデックスの最適化に集中するのは正しいことです。
パイプライン演算子とインデックスを参照してください。
更新 2
集計と説明の詳細: バージョン 2.4 では信頼性が低くなります。2.6 以降では、クエリ実行データは提供されません。https://groups.google.com/forum/#!topic/mongodb-user/2LzAkyaNqe0
更新 1
MongoDB 2.4.5 に関する集計の説明のトランスクリプト。
$ mongo so
MongoDB shell version: 2.4.5
connecting to: so
> db.q19329239.runCommand("aggregate", {pipeline: [{$group: {_id: '$user.id', hits: {$sum: 1}}}, {$match: {hits: {$gt: 10}}}], explain: true})
{
"serverPipeline" : [
{
"query" : {
},
"projection" : {
"user.id" : 1,
"_id" : 0
},
"cursor" : {
"cursor" : "BasicCursor",
"isMultiKey" : false,
"n" : 1031,
"nscannedObjects" : 1031,
"nscanned" : 1031,
"nscannedObjectsAllPlans" : 1031,
"nscannedAllPlans" : 1031,
"scanAndOrder" : false,
"indexOnly" : false,
"nYields" : 0,
"nChunkSkips" : 0,
"millis" : 0,
"indexBounds" : {
},
"allPlans" : [
{
"cursor" : "BasicCursor",
"n" : 1031,
"nscannedObjects" : 1031,
"nscanned" : 1031,
"indexBounds" : {
}
}
],
"server" : "ficrm-rafa.local:27017"
}
},
{
"$group" : {
"_id" : "$user.id",
"hits" : {
"$sum" : {
"$const" : 1
}
}
}
},
{
"$match" : {
"hits" : {
"$gt" : 10
}
}
}
],
"ok" : 1
}
サーバーのバージョン。
$ mongo so
MongoDB shell version: 2.4.5
connecting to: so
> db.version()
2.4.5