Occasional spike in nscanned for a MongoDB query -


i have query of form

db.coll.find({x: {$in: ['foo', 'bar', 'baz']}).sort({_id:-1}).limit(limit) 

"x" single objectid field, _id objectid too. there index {x:1, _id:-1}. query should hitting fast path #server-5063.

it of time, except rare instances appears full table scan performed - profile entry these queries shows nscanned above count of documents matching {x: {$in: ['foo', 'bar', 'baz']}}. that's 3 orders of magnitude above query scans in expected case.

the collection write heavy, first guess perhaps query optimizer retrying various query plans, including {_id:1} index, spikes remain after adding .hint({x:1, _id:-1}), i'm not sure what's going on here.

can explain occasional scan of documents matching query , how prevent it?

edit: happens on mongodb 2.4.4


Comments