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

Query misses results with .sort()

    • Type: Icon: Bug Bug
    • Resolution: Done
    • Priority: Icon: Critical - P2 Critical - P2
    • 2.6.0-rc3
    • Affects Version/s: 2.6.0-rc2
    • Component/s: Index Maintenance
    • Labels:
      None
    • ALL

      Please see the queries below performed on 2.6.0-rc2. When the query includes a .sort() no records are returned. When the .sort() is removed, the expected records are returned. The .explain() on the sorted version looks quite strange to me.

      > db.version()
      2.6.0-rc2
      > db.config.users.find({},{un:1,pe:1,cre:1})
      { "_id" : ObjectId("53362b393004cde05e1ae35c"), "un" : "cailin.nelson@10gen.com", "cre" : ISODate("2014-03-29T02:08:57.062Z"), "pe" : "cailin.nelson@10gen.com" }
      { "_id" : ObjectId("533633aa300495bc76c058cb"), "un" : "cowboy@johnandcailin.com", "cre" : ISODate("2014-03-29T02:44:58.941Z"), "pe" : "cowboy@johnandcailin.com" }
      { "_id" : ObjectId("533633b2300495bc76c058d1"), "un" : "alberta@johnandcailin.com", "cre" : ISODate("2014-03-29T02:45:06.299Z"), "pe" : "alberta@johnandcailin.com" }
      > db.config.users.find({$or:[{un: /cailin/},{pe:/cailin/}]},{un:1}).sort({cre:-1}).limit(10).skip(0).count()
      3
      > db.config.users.find({$or:[{un: /cailin/},{pe:/cailin/}]},{un:1}).sort({cre:-1}).limit(10).skip(0)
      > db.config.users.find({$or:[{un: /cailin/},{pe:/cailin/}]},{un:1}).sort({cre:-1}).limit(10).skip(0).explain()
      {
      	"cursor" : "BtreeCursor createdIdx reverse",
      	"isMultiKey" : false,
      	"n" : 0,
      	"nscannedObjects" : 0,
      	"nscanned" : 1,
      	"nscannedObjectsAllPlans" : 0,
      	"nscannedAllPlans" : 1,
      	"scanAndOrder" : false,
      	"indexOnly" : false,
      	"nYields" : 0,
      	"nChunkSkips" : 0,
      	"millis" : 0,
      	"indexBounds" : {
      		"cre" : [
      			[
      				/cailin/,
      				/cailin/
      			],
      			[
      				{
      					
      				},
      				""
      			]
      		]
      	},
      	"server" : "cailinmac:27017",
      	"filterSet" : false
      }
      > db.config.users.find({$or:[{un: /cailin/},{pe:/cailin/}]},{un:1}).limit(10).skip(0)
      { "_id" : ObjectId("533633b2300495bc76c058d1"), "un" : "alberta@johnandcailin.com" }
      { "_id" : ObjectId("53362b393004cde05e1ae35c"), "un" : "cailin.nelson@10gen.com" }
      { "_id" : ObjectId("533633aa300495bc76c058cb"), "un" : "cowboy@johnandcailin.com" }
      > 
      

      If I downgrade to 2.4.6, then the expected results are returned with the .sort()

      [scripts] (feature_mmsp_1468)$ mongo
      MongoDB shell version: 2.4.6
      connecting to: test
      > db.version()
      2.4.6
      > use mmsdbconfig
      switched to db mmsdbconfig
      > db.config.users.find({},{un:1,pe:1,cre:1})
      { "_id" : ObjectId("53362b393004cde05e1ae35c"), "un" : "cailin.nelson@10gen.com", "cre" : ISODate("2014-03-29T02:08:57.062Z"), "pe" : "cailin.nelson@10gen.com" }
      { "_id" : ObjectId("533633aa300495bc76c058cb"), "un" : "cowboy@johnandcailin.com", "cre" : ISODate("2014-03-29T02:44:58.941Z"), "pe" : "cowboy@johnandcailin.com" }
      { "_id" : ObjectId("533633b2300495bc76c058d1"), "un" : "alberta@johnandcailin.com", "cre" : ISODate("2014-03-29T02:45:06.299Z"), "pe" : "alberta@johnandcailin.com" }
      > db.config.users.find({$or:[{un: /cailin/},{pe:/cailin/}]},{un:1}).sort({cre:-1}).limit(10).skip(0)
      { "_id" : ObjectId("533633b2300495bc76c058d1"), "un" : "alberta@johnandcailin.com" }
      { "_id" : ObjectId("533633aa300495bc76c058cb"), "un" : "cowboy@johnandcailin.com" }
      { "_id" : ObjectId("53362b393004cde05e1ae35c"), "un" : "cailin.nelson@10gen.com" }
      

            Assignee:
            hari.khalsa@10gen.com hari.khalsa@10gen.com
            Reporter:
            cailin.nelson@mongodb.com Cailin Nelson
            Votes:
            0 Vote for this issue
            Watchers:
            7 Start watching this issue

              Created:
              Updated:
              Resolved: