Slow MongoDB query: can you explain why?

强颜欢笑 提交于 2019-12-01 07:40:42

问题


I have a MongoDB query that's taking an unreasonably long time to run, but it:

  • is only scanning 6 objects
  • hits an index
  • consistently takes ~1500ms (wasn't paging or otherwise occupied)
  • index miss% is 0 in mongostat

It showed up in the profiler (without the explain()), and I don't understand why it's so slow. Any ideas?

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
                }
            ]
        ]
    }
}

回答1:


Missing the index on the private key?

BtreeCursor owner_1_avatar_1_date_-1 vs .find({ owner: "123", avatar: false, private: false }).sort({date: -1})



来源:https://stackoverflow.com/questions/8720535/slow-mongodb-query-can-you-explain-why

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!