我使用Mongo Java驱动程序编写了一个MongoDB索引,如下所示:
MongoClient mongoClient = new MongoClient("localhost", 27017);
DB db = mongoClient.getDB("test");
DBCollection coll = db.getCollection("indexdemo");
coll.createIndex(new BasicDBObject("code",1));
for (int ii=0;ii<100000;ii++) {
DBObject doc = new BasicDBObject("code", ii);
coll.insert(doc);
}
当我执行索引的解释计划(MongoDB 3.x)时,似乎可以识别索引边界但是totalKeysExamined是0并且totalDocsExamined也是0
db.indextest.find({code: 5000}).explain("executionStats")
{
. . . .
"executionStats":{
"executionSuccess":true,
"nReturned":0,
"executionTimeMillis":0,
"totalKeysExamined":0,
"totalDocsExamined":0,
"executionStages":{
"stage":"FETCH",
"nReturned":0,
"executionTimeMillisEstimate":0,
"works":1,
"advanced":0,
"needTime":0,
"needFetch":0,
"saveState":0,
"restoreState":0,
"isEOF":1,
"invalidates":0,
"docsExamined":0,
"alreadyHasObj":0,
"inputStage":{
"stage":"IXSCAN",
"nReturned":0,
"executionTimeMillisEstimate":0,
"works":1,
"advanced":0,
"needTime":0,
"needFetch":0,
"saveState":0,
"restoreState":0,
"isEOF":1,
"invalidates":0,
"keyPattern":{
"code":1
},
"indexName":"userid_1",
"isMultiKey":false,
"direction":"forward",
"indexBounds":{
"code":[
"[\"1111\", \"1111\"]"
]
},
"keysExamined":0,
"dupsTested":0,
"dupsDropped":0,
"seenInvalidated":0,
"matchTested":0
}
},
"allPlansExecution":[
]
},
答案 0 :(得分:1)
如果按索引只有一个匹配,则defenitely得到totalKeysExamined = 1和totalDocsExamined = 1。