ISSUE SUMMARY
Given a compound index on a collection, queries producing empty results over a field fail if there's a subsequent sort stage over the next field in the index. Here are two examples with the $in operator:
db.col.ensureIndex({a : 1, b : 1, c : 1})
|
db.col.find({a : {$in : []}}).sort({b : 1})
|
db.col.find({a : 1, b : {$in : []}}).sort({c : 1})
|
Other queries yielding empty bounds will also trigger the issue. For example, if you have non-multikey index {a: 1, b: 1, c: 1}, the assert will be triggered by:
db.col.find({a : {$gt : 5, $lt : 4}}).sort({b : 1})
|
db.col.find({a : 1, b : {$gt : 5, $lt : 4}}).sort({c : 1})
|
USER IMPACT
Queries of this type fail with an assertion error. Queries of this type should be extremely rare, as the result is always empty.
WORKAROUNDS
There are no known workarounds.
AFFECTED VERSIONS
MongoDB production releases 2.6.0 and 2.6.1 are affected by this issue.
FIX VERSION
The fix is included in the 2.6.2 production release.
RESOLUTION DETAILS
Do not attempt to explode for sort with empty bounds.