Uploaded image for project: 'Core Server'
  1. Core Server
  2. SERVER-14175

After creating an index in a capped collection, sorting it in reverse natural order doesn't work anymore

    • Type: Icon: Bug Bug
    • Resolution: Duplicate
    • Priority: Icon: Major - P3 Major - P3
    • None
    • Affects Version/s: 2.6.1
    • Component/s: Querying
    • None
    • ALL
    • Hide
      > 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 }
      >
      Show
      > 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 } >

      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

            Assignee:
            david.storch@mongodb.com David Storch
            Reporter:
            cezarsa Cezar Sá Espinola
            Votes:
            0 Vote for this issue
            Watchers:
            5 Start watching this issue

              Created:
              Updated:
              Resolved: