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

Regression from 2.4.x -> 2.6.x in order of $or

    • Type: Icon: Bug Bug
    • Resolution: Done
    • Priority: Icon: Major - P3 Major - P3
    • None
    • Affects Version/s: 2.6.0
    • Component/s: Querying
    • Labels:
      None
    • ALL
    • Hide
      db.collection.insert({ position: 1 })
      db.collection.insert({ position: 2 })
      
      var ids = db.collection.find({}, { _id: 1 }).sort({ _id: -1 }).map(function(doc) { return { _id: doc._id } })
      db.collection.find({ $or : ids })
      
      ---
      
      ## 2.4.10
      
      joe@li245-114:~$ mongo
      MongoDB shell version: 2.4.10
      connecting to: test
      > db.collection.insert({ position: 1 })
      > db.collection.insert({ position: 2 })
      > 
      > var ids = db.collection.find({}, { _id: 1 }).sort({ _id: -1 }).map(function(doc) { return { _id: doc._id } })
      > db.collection.find({ $or : ids })
      { "_id" : ObjectId("538748f9b637c258c6964136"), "position" : 2 }
      { "_id" : ObjectId("538748f9b637c258c6964135"), "position" : 1 }
      
      
      ## 2.6.0
      
      > db.collection.insert({ position: 1 })
      WriteResult({ "nInserted" : 1 })
      > db.collection.insert({ position: 2 })
      WriteResult({ "nInserted" : 1 })
      > 
      > var ids = db.collection.find({}, { _id: 1 }).sort({ _id: -1 }).map(function(doc) { return { _id: doc._id } })
      > db.collection.find({ $or : ids })
      { "_id" : ObjectId("538749a82aa9f7bc4f6dd565"), "position" : 1 }
      { "_id" : ObjectId("538749a82aa9f7bc4f6dd566"), "position" : 2 }
      
      
      Show
      db.collection.insert({ position: 1 }) db.collection.insert({ position: 2 }) var ids = db.collection.find({}, { _id: 1 }).sort({ _id: -1 }).map(function(doc) { return { _id: doc._id } }) db.collection.find({ $or : ids }) --- ## 2.4.10 joe@li245-114:~$ mongo MongoDB shell version: 2.4.10 connecting to: test > db.collection.insert({ position: 1 }) > db.collection.insert({ position: 2 }) > > var ids = db.collection.find({}, { _id: 1 }).sort({ _id: -1 }).map(function(doc) { return { _id: doc._id } }) > db.collection.find({ $or : ids }) { "_id" : ObjectId( "538748f9b637c258c6964136" ), "position" : 2 } { "_id" : ObjectId( "538748f9b637c258c6964135" ), "position" : 1 } ## 2.6.0 > db.collection.insert({ position: 1 }) WriteResult({ "nInserted" : 1 }) > db.collection.insert({ position: 2 }) WriteResult({ "nInserted" : 1 }) > > var ids = db.collection.find({}, { _id: 1 }).sort({ _id: -1 }).map(function(doc) { return { _id: doc._id } }) > db.collection.find({ $or : ids }) { "_id" : ObjectId( "538749a82aa9f7bc4f6dd565" ), "position" : 1 } { "_id" : ObjectId( "538749a82aa9f7bc4f6dd566" ), "position" : 2 }

      We used to rely on $or to return an ordered result set. 2.6.? no longer does that.

      I understand that was never documented as a feature, but it's pretty clear that lots of people do that , see http://stackoverflow.com/questions/3142260/order-of-responses-to-mongodb-in-query for example.

            Assignee:
            david.storch@mongodb.com David Storch
            Reporter:
            dblock Daniel Doubrovkine
            Votes:
            0 Vote for this issue
            Watchers:
            7 Start watching this issue

              Created:
              Updated:
              Resolved: