scoates
scoates

Reputation: 853

Slow MongoDB query: can you explain why?

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

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

Upvotes: 3

Views: 1337

Answers (1)

nav
nav

Reputation: 3125

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

Upvotes: 4

Related Questions