我有一个MongoDB查询需要花费不合理的长时间才能运行,但它:
它出现在探查器中(没有explain()),我不明白为什么它这么慢。有什么想法吗?
gimmebar:PRIMARY> db.assets.find({ owner: "123", avatar: false, private: false }).sort({date: -1}).explain()
{
"cursor" : "BtreeCursor owner_1_avatar_1_date_-1",
"nscanned" : 6,
"nscannedObjects" : 6,
"n" : 6,
"millis" : 1567,
"nYields" : 0,
"nChunkSkips" : 0,
"isMultiKey" : false,
"indexOnly" : false,
"indexBounds" : {
"owner" : [
[
"123",
"123"
]
],
"avatar" : [
[
false,
false
]
],
"date" : [
[
{
"$maxElement" : 1
},
{
"$minElement" : 1
}
]
]
}
}
答案 0 :(得分:4)
缺少private
键上的索引?
BtreeCursor owner_1_avatar_1_date_-1
vs .find({ owner: "123", avatar: false, private: false }).sort({date: -1})