私は今朝の大半を MongoDBのdocs、blog、およびスタック上の他の回答を再読することに費やしましたが、他の人にとって痛々しいほど明白であることを願っている何かがまだ欠けています。
編集: サブドキュメント (メタデータ.*) を持たないようにドキュメントのスキームを変更しましたが、インデックスがカバーされていないという問題がまだあります。既存のインデックスを削除し、新しいインデックスで再インデックスしました。
だから私は持っていません:
[
{
"v" : 1,
"key" : {
"_id" : 1
},
"name" : "_id_",
"ns" : "test.daily"
},
{
"v" : 1,
"key" : {
"host" : 1,
"cid" : 1,
"title" : 1,
"urls" : 1,
"global" : -1,
"current" : -1,
"total" : -1
},
"name" : "byHostTotals",
"ns" : "test.daily"
},
{
"v" : 1,
"key" : {
"host" : 1,
"cid" : 1,
"title" : 1,
"urls" : 1,
"total" : -1,
"global" : -1,
"current" : -1
},
"name" : "byHostCurrents",
"ns" : "test.daily"
}
]
そして、次のクエリが与えられます:
db.daily.find({'host': 'example.com'}, {'_id': 0, 'cid': 1, 'title': 1, 'current': 1}).hint("byHostCurrents").sort({'current': -1}).limit(10).explain()
「byHostCurrent」という名前のインデックスでカバーされているものとして表示されません。
{
"clauses" : [
{
"cursor" : "BtreeCursor byHostCurrents",
"isMultiKey" : true,
"n" : 10,
"nscannedObjects" : 1090,
"nscanned" : 1111,
"scanAndOrder" : true,
"indexOnly" : false,
"nChunkSkips" : 0,
"indexBounds" : {
"host" : [
[
"example.com",
"example.com"
]
],
"cid" : [
[
{
"$minElement" : 1
},
{
"$maxElement" : 1
}
]
],
"title" : [
[
{
"$minElement" : 1
},
{
"$maxElement" : 1
}
]
],
"total" : [
[
{
"$maxElement" : 1
},
{
"$minElement" : 1
}
]
],
"global" : [
[
{
"$maxElement" : 1
},
{
"$minElement" : 1
}
]
],
"current" : [
[
{
"$maxElement" : 1
},
{
"$minElement" : 1
}
]
]
}
},
{
"cursor" : "BtreeCursor ",
"isMultiKey" : false,
"n" : 0,
"nscannedObjects" : 0,
"nscanned" : 0,
"scanAndOrder" : true,
"indexOnly" : false,
"nChunkSkips" : 0,
"indexBounds" : {
"host" : [
[
"usatoday.com",
"usatoday.com"
]
],
"cid" : [
[
{
"$minElement" : 1
},
{
"$maxElement" : 1
}
]
],
"title" : [
[
{
"$minElement" : 1
},
{
"$maxElement" : 1
}
]
],
"total" : [
[
{
"$maxElement" : 1
},
{
"$minElement" : 1
}
]
],
"global" : [
[
{
"$maxElement" : 1
},
{
"$minElement" : 1
}
]
],
"current" : [
[
{
"$maxElement" : 1
},
{
"$minElement" : 1
}
]
]
}
}
],
"cursor" : "QueryOptimizerCursor",
"n" : 10,
"nscannedObjects" : 1090,
"nscanned" : 1111,
"nscannedObjectsAllPlans" : 1090,
"nscannedAllPlans" : 1111,
"scanAndOrder" : false,
"nYields" : 8,
"nChunkSkips" : 0,
"millis" : 9,
"server" : "ubuntu:27017",
"filterSet" : false
}
MongoDB のバージョンは 2.6.3 です。