我有一个简单的集合customers
,如下所示
db.customers.find().pretty()
{
"_id" : ObjectId("524eb09ca71b72672e65ebb6"),
"name" : "kiran",
"occupation" : "SelfEmployeed",
"country" : "IND"
}
{
"_id" : ObjectId("524eb0a4a71b72672e65ebb7"),
"name" : "Mark",
"occupation" : "Architect",
"country" : "US"
}
{
"_id" : ObjectId("524eb0aba71b72672e65ebb8"),
"name" : "beast",
"occupation" : "housewife",
"country" : "UK"
}
{
"_id" : ObjectId("524eb0b2a71b72672e65ebb9"),
"name" : "Philip",
"occupation" : "Engineer",
"country" : "SWE"
}
我在名称和国家字段上创建了索引,如下所示
db.customers.ensureIndex({name : 1}, {"unique" : false})
db.customers.ensureIndex({country : 1}, {"unique" : false})
索引已创建
db.customers.getIndexKeys()
[ {“_id”:1 },{“名称”:1 },{“国家”:1 }]
这是我的查询解释的结果
db.customers.find({name : "Mark"}).explain()
{
"cursor" : "BtreeCursor name_1",
"isMultiKey" : false,
"n" : 1,
"nscannedObjects" : 1,
"nscanned" : 1,
"nscannedObjectsAllPlans" : 1,
"nscannedAllPlans" : 1,
"scanAndOrder" : false,
"indexOnly" : false,
"nYields" : 0,
"nChunkSkips" : 0,
"millis" : 0,
"indexBounds" : {
"name" : [
[
"Mark",
"Mark"
]
]
},
"server" : "************"
}
为什么 indexonly 属性值为 false ?
我看到了类似的问题,解释了这是由于
indexonly 是错误的,因为它不会仅使用索引,因为您将通过该查询检索未编入索引的其他字段。
请让我知道这里的其他字段是什么意思?