gpt4 book ai didi

mongodb - 如何索引 $and operator over $or operator

转载 作者:可可西里 更新时间:2023-11-01 10:44:20 25 4
gpt4 key购买 nike

早上好。我有一些问题。我有这些字段:

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...它如何修复?

最佳答案

可能是时候升级您的 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"
]
]
}
}

关于mongodb - 如何索引 $and operator over $or operator,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17008247/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com