[SERVER-14175] After creating an index in a capped collection, sorting it in reverse natural order doesn't work anymore Created: 05/Jun/14  Updated: 10/Dec/14  Resolved: 05/Jun/14

Status: Closed
Project: Core Server
Component/s: Querying
Affects Version/s: 2.6.1
Fix Version/s: None

Type: Bug Priority: Major - P3
Reporter: Cezar Sá Espinola Assignee: David Storch
Resolution: Duplicate Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Duplicate
duplicates SERVER-14176 natural order sort specification igno... Closed
Operating System: ALL
Steps To Reproduce:

> db.createCollection("mycoll", {capped: true, size: 100000, max: 1000})
{ "ok" : 1 }
 
> for(var i = 0; i < 100; ++i) { db.mycoll.insert({x: i}); }
WriteResult({ "nInserted" : 1 })
 
> db.mycoll.ensureIndex({x: 1})
{
    "createdCollectionAutomatically" : false,
    "numIndexesBefore" : 1,
    "numIndexesAfter" : 2,
    "ok" : 1
}
 
So far so good:
 
> db.mycoll.find({x:{$gt:95}}).sort({$natural: 1})
{ "_id" : ObjectId("5390738c8f5c62869f0775ad"), "x" : 96 }
{ "_id" : ObjectId("5390738c8f5c62869f0775ae"), "x" : 97 }
{ "_id" : ObjectId("5390738c8f5c62869f0775af"), "x" : 98 }
{ "_id" : ObjectId("5390738c8f5c62869f0775b0"), "x" : 99 }
 
Oops:
 
> db.mycoll.find({x:{$gt:95}}).sort({$natural: -1})
{ "_id" : ObjectId("5390738c8f5c62869f0775ad"), "x" : 96 }
{ "_id" : ObjectId("5390738c8f5c62869f0775ae"), "x" : 97 }
{ "_id" : ObjectId("5390738c8f5c62869f0775af"), "x" : 98 }
{ "_id" : ObjectId("5390738c8f5c62869f0775b0"), "x" : 99 }
>

Participants:

 Description   

After creating an index in a capped collection, sorting it in reverse natural order doesn't work anymore. The result is always sorted in natural order instead.

See https://gist.github.com/cezarsa/0c1106ee32ee7b12914c for more details

Version:
$ mongod --version
db version v2.6.1
2014-06-05T13:45:27.884+0000 git version: 4b95b086d2374bdcfcdf2249272fb552c9c726e8



 Comments   
Comment by hari.khalsa@10gen.com [ 05/Jun/14 ]

Going to address in the linked ticket.

Generated at Thu Feb 08 03:34:04 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.