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

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

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Major - P3
    • Resolution: Works as Designed
    • Affects Version/s: 2.6.0
    • Fix Version/s: None
    • Component/s: Querying
    • Labels:
      None
    • Operating System:
      ALL
    • Steps To Reproduce:
      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 }  

      Description

      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.

        Attachments

          Activity

            People

            Assignee:
            david.storch David Storch
            Reporter:
            dblock Daniel Doubrovkine
            Participants:
            Votes:
            0 Vote for this issue
            Watchers:
            8 Start watching this issue

              Dates

              Created:
              Updated:
              Resolved: