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

Array sort semantics

    • Type: Icon: Bug Bug
    • Resolution: Done
    • Priority: Icon: Minor - P4 Minor - P4
    • None
    • Affects Version/s: None
    • Component/s: None
    • Labels:
      None
    • ALL

      We should clearly define the sort semantics for unindexed arrays. There's a discrepancy here:

      > db.g.find().sort({a:-1})
      { "_id" : ObjectId("4f88436904495dab8a55071c"), "a" : [ 4 ] }
      { "_id" : ObjectId("4f88436804495dab8a55071b"), "a" : [ 3 ] }
      { "_id" : ObjectId("4f88436704495dab8a55071a"), "a" : [ 2 ] }
      { "_id" : ObjectId("4f88436504495dab8a550719"), "a" : [ 1 ] }
      { "_id" : ObjectId("4f88438604495dab8a55071d"), "a" : [ 1, 1 ] }
      { "_id" : ObjectId("4f88439c04495dab8a55071e"), "a" : [ 1, 1, 0 ] }
      { "_id" : ObjectId("4f88440204495dab8a55071f"), "a" : [ 1, 1, 0, 1 ] }
      { "_id" : ObjectId("4f88441104495dab8a550720"), "a" : [ 1, 1, 1, 1 ] }
      
      > db.g.find().sort({a:1})
      { "_id" : ObjectId("4f88439c04495dab8a55071e"), "a" : [ 1, 1, 0 ] }
      { "_id" : ObjectId("4f88440204495dab8a55071f"), "a" : [ 1, 1, 0, 1 ] }
      { "_id" : ObjectId("4f88436504495dab8a550719"), "a" : [ 1 ] }
      { "_id" : ObjectId("4f88438604495dab8a55071d"), "a" : [ 1, 1 ] }
      { "_id" : ObjectId("4f88441104495dab8a550720"), "a" : [ 1, 1, 1, 1 ] }
      { "_id" : ObjectId("4f88436704495dab8a55071a"), "a" : [ 2 ] }
      { "_id" : ObjectId("4f88436804495dab8a55071b"), "a" : [ 3 ] }
      { "_id" : ObjectId("4f88436904495dab8a55071c"), "a" : [ 4 ] }
      

      It seems that the reverse sort should mirror the forward sort, but it doesn't.

            Assignee:
            Unassigned Unassigned
            Reporter:
            kbanker Kyle Banker
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved: