-
Type: Bug
-
Resolution: Duplicate
-
Priority: Major - P3
-
None
-
Affects Version/s: 2.4.3, 2.4.7
-
Component/s: Querying
-
ALL
Setting the .min() or .max() explicitly on a find and using a descending sort seems not to work.
> db.docs.drop() > for (var i=0; i<10; i++) { db.docs.insert({number: i}) } > db.docs.ensureIndex({number: 1})
no sort
> db.docs.find().max({number: 4}) { "_id" : ObjectId("51834d678d284e5c5e3ea7e3"), "number" : 0 } { "_id" : ObjectId("51834d678d284e5c5e3ea7e4"), "number" : 1 } { "_id" : ObjectId("51834d678d284e5c5e3ea7e5"), "number" : 2 } { "_id" : ObjectId("51834d678d284e5c5e3ea7e6"), "number" : 3 }
ascending sort
> db.docs.find().max({number: 4}).sort({number: 1}) { "_id" : ObjectId("51834d678d284e5c5e3ea7e3"), "number" : 0 } { "_id" : ObjectId("51834d678d284e5c5e3ea7e4"), "number" : 1 } { "_id" : ObjectId("51834d678d284e5c5e3ea7e5"), "number" : 2 } { "_id" : ObjectId("51834d678d284e5c5e3ea7e6"), "number" : 3 }
descending sort
> db.docs.find().max({number: 4}).sort({number: -1}) >
I would expect to get the 4 documents back in the 'reverse order' case, in number order: 3, 2, 1, 0. Instead, I get 0 documents back.
explain of ascending sort
> db.docs.find().max({number: 4}).sort({number: 1}).explain() { "cursor" : "BtreeCursor number_1", "isMultiKey" : false, "n" : 4, "nscannedObjects" : 4, "nscanned" : 4, "nscannedObjectsAllPlans" : 4, "nscannedAllPlans" : 4, "scanAndOrder" : false, "indexOnly" : false, "nYields" : 0, "nChunkSkips" : 0, "millis" : 0, "indexBounds" : { "start" : { "number" : { "$minElement" : 1 } }, "end" : { "number" : 4 } }, "server" : "capslock.local:27017" }
explain of descending sort
> db.docs.find().max({number: 4}).sort({number: -1}).explain() { "cursor" : "BtreeCursor number_1 reverse", "isMultiKey" : false, "n" : 0, "nscannedObjects" : 0, "nscanned" : 0, "nscannedObjectsAllPlans" : 0, "nscannedAllPlans" : 0, "scanAndOrder" : false, "indexOnly" : false, "nYields" : 0, "nChunkSkips" : 0, "millis" : 0, "indexBounds" : { "start" : { "number" : { "$minElement" : 1 } }, "end" : { "number" : 4 } }, "server" : "capslock.local:27017" }
- depends on
-
SERVER-3766 Assertion failure la <= 0xffffff db/btree.h when creating BtreeCursor with direction -1 and max/min bounds
- Closed
-
SERVER-10026 New query system
- Closed
- duplicates
-
SERVER-15015 Assertion failure when combining $max/$min and reverse index scan
- Closed
- is duplicated by
-
SERVER-9540 How to get the previous mongoDB document from a compound index
- Closed
- is related to
-
SERVER-17076 Consider removing IndexBounds::isSimpleRange
- Closed
- related to
-
SERVER-15015 Assertion failure when combining $max/$min and reverse index scan
- Closed