早上好。我有一些问题。我有这些领域:
name: "Mike",
city: "NY",
address: "something",
pets: ["dog", "cat"]
我创建了索引
db.person.ensureIndex({name: 1})
db.person.ensureIndex({city: 1})
db.person.ensureIndex({address: 1})
db.person.ensureIndex({pets: 1})
查询是
db.person.find({$and: [{$or: [{name: "Mike"}, {city: "CA"}]}, {pets: "dog"}]}).explain()
我没有得到B_tree查询..我得到了BasicCursor ......如何解决?
答案 0 :(得分:1)
可能是升级MongoDB版本的时候了。使用v2.2.1我得到一个BTree游标。
> db.person.insert({name: "Mike", city: "NY", address: "something", pets: ["dog", "cat"]})
> db.person.ensureIndex({name: 1})
> db.person.ensureIndex({city: 1})
> db.person.ensureIndex({address: 1})
> db.person.ensureIndex({pets: 1})
> db.person.find({$and: [{$or: [{name: "Mike"}, {city: "CA"}]}, {pets: "dog"}]}).explain()
{
"cursor" : "BtreeCursor pets_1",
"isMultiKey" : true,
"n" : 1,
"nscannedObjects" : 1,
"nscanned" : 1,
"nscannedObjectsAllPlans" : 1,
"nscannedAllPlans" : 1,
"scanAndOrder" : false,
"indexOnly" : false,
"nYields" : 0,
"nChunkSkips" : 0,
"millis" : 0,
"indexBounds" : {
"pets" : [
[
"dog",
"dog"
]
]
}
}