|
The indexOnly in an explain() is set to true even if the query needs fields which aren't in the index.
This is the example collection:
db.test.insert([{a:1,c:1},{a:2,c:1}])
|
db.test.ensureIndex({c:1})
|
db.test.find({a:1,c:1},{_id:0,c:1}).explain()
|
This is what the explain looks like:
> db.test.find({a:1,c:1},{_id:0,c:1}).explain()
|
{
|
"cursor" : "BtreeCursor c_1",
|
"isMultiKey" : false,
|
"n" : 1,
|
"nscannedObjects" : 2,
|
"nscanned" : 2,
|
"nscannedObjectsAllPlans" : 4,
|
"nscannedAllPlans" : 4,
|
"scanAndOrder" : false,
|
"indexOnly" : true,
|
"nYields" : 0,
|
"nChunkSkips" : 0,
|
"millis" : 0,
|
"indexBounds" : {
|
"c" : [
|
[
|
1,
|
1
|
]
|
]
|
},
|
"server" : "server:27017"
|
}
|
indexOnly is set to true but MongoDB has to query on field a which is not part of the index c_1 - so it has to be false.
|