在 MongoDB 中,我有以下简单查询,在 postTime:-1 上有一个索引。该集合有 100,237 个文档。explain() 表示查询完全被索引覆盖。
为什么 nScannedObjects 是 100,237?此外,即使我只对前 5 个结果感兴趣,查询时间也是 455 毫秒。
我做错了什么,或者这就是 MongoDB 的工作方式?有人可以解释为什么索引查询需要这么长时间吗?
谢谢 :) 莱斯
db.guestBookPost.find({ postTime : {$gte : 0}, $orderby : { "postTime" : -1}}, {_id:0, >postTime:1}).limit(5).explain()
{
"cursor" : "BtreeCursor postTime_-1",
"isMultiKey" : false,
"n" : 0,
"nscannedObjects" : 100237,
"nscanned" : 100237,
"nscannedObjectsAllPlans" : 200474,
"nscannedAllPlans" : 200474,
"scanAndOrder" : false,
"indexOnly" : true,
"nYields" : 0,
"nChunkSkips" : 0,
"millis" : 455,
"indexBounds" : {
"postTime" : [
[
1.7976931348623157e+308,
0
]
]
},
"server" : "ip-10-245-26-151:27017"
}