それは面白かったです。それがバグであるかどうかはあなた次第だとは言えません。
使用可能な構文は2つあります。
使用する場合:
db.collection.find( { age : 25 } )
また
db.collection.find( { age : 25 } ).explain()
db.collection.find( { age : 25 } ).hint(someindex)
正常に動作します。
ソリューション(他の構文)を使用する場合:
db.collection.find( { $query: { age : 25 } } )
の出力
db.sampleCollection.find({$query:{"stringField":"Random string0"}}).explain()
インデックスを使用していないクエリのように表示されます
インデックスに.hintも使用すると、結果が省略されます。 :)(それは私が本当に理解していないということです)
幸い、これらの操作には別の構文もあります。次を使用できます:
db.sampleCollection.find({$query:{"stringField":"Random string0"}, $explain:1})
正しい出力が得られ、インデックスの使用法が示されます。 $hintにも同様の構文があります。
ここでドキュメントを確認できます: http://docs.mongodb.org / manual / reference / meta-query-operators /
これは本当に面白いと思ったので、プロファイラーをオンにしました:
約25万件のドキュメントを含むテストコレクション(queryTst)を作成しました。各ドキュメントには、_idと、年齢のインデックスを持つ構造内の年齢フィールドのみが含まれています。
このクエリの場合:
db.queryTst.find({$query:{"age":16},$explain:1})
入手した:
{
"cursor" : "BtreeCursor age_1",
"isMultiKey" : false,
"n" : 2,
"nscannedObjects" : 2,
"nscanned" : 2,
"nscannedObjectsAllPlans" : 2,
"nscannedAllPlans" : 2,
"scanAndOrder" : false,
"indexOnly" : false,
"nYields" : 0,
"nChunkSkips" : 0,
"millis" : 0,
"indexBounds" : {
"age" : [
[
16,
16
]
]
},
"allPlans" : [
{
"cursor" : "BtreeCursor age_1",
"n" : 2,
"nscannedObjects" : 2,
"nscanned" : 2,
"indexBounds" : {
"age" : [
[
16,
16
]
]
}
}
],
"oldPlan" : {
"cursor" : "BtreeCursor age_1",
"indexBounds" : {
"age" : [
[
16,
16
]
]
}
},
"server" : ""
}
このために:
db.queryTst.find({$query:{"age":16},$explain:1}).explain()
入手した:
"cursor" : "BasicCursor",
"isMultiKey" : false,
"n" : 0,
"nscannedObjects" : 250011,
"nscanned" : 250011,
"nscannedObjectsAllPlans" : 250011,
"nscannedAllPlans" : 250011,
"scanAndOrder" : false,
"indexOnly" : false,
"nYields" : 0,
"nChunkSkips" : 0,
"millis" : 103,
"indexBounds" : {
},
プロファイラーログ:最初の
{
"ts" : ISODate("2013-01-30T20:35:40.526Z"),
"op" : "query",
"ns" : "test.queryTst",
"query" : {
"$query" : {
"age" : 16
},
"$explain" : 1
},
"ntoreturn" : 0,
"ntoskip" : 0,
"nscanned" : 2,
"keyUpdates" : 0,
"numYield" : 0,
"lockStats" : {
"timeLockedMicros" : {
"r" : NumberLong(368),
"w" : NumberLong(0)
},
"timeAcquiringMicros" : {
"r" : NumberLong(8),
"w" : NumberLong(5)
}
},
"nreturned" : 1,
"responseLength" : 567,
"millis" : 0,
"client" : "127.0.0.1",
"user" : ""
}
2番目の場合:
{
"ts" : ISODate("2013-01-30T20:35:47.715Z"),
"op" : "query",
"ns" : "test.queryTst",
"query" : {
"query" : {
"$query" : {
"age" : 16
},
"$explain" : 1
},
"$explain" : true
},
"ntoreturn" : 0,
"ntoskip" : 0,
"nscanned" : 250011,
"keyUpdates" : 0,
"numYield" : 0,
"lockStats" : {
"timeLockedMicros" : {
"r" : NumberLong(104092),
"w" : NumberLong(0)
},
"timeAcquiringMicros" : {
"r" : NumberLong(13),
"w" : NumberLong(5)
}
},
"nreturned" : 1,
"responseLength" : 373,
"millis" : 104,
"client" : "127.0.0.1",
"user" : ""
}
これはどういうわけか私にとって、explain()が混合構文でテーブルスキャンを引き起こすことを意味します。