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

Array sort semantics

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Minor - P4
    • Resolution: Works as Designed
    • Affects Version/s: None
    • Fix Version/s: None
    • Component/s: None
    • Labels:
      None
    • Operating System:
      ALL

      Description

      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.

        Attachments

          Activity

            People

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

              Dates

              Created:
              Updated:
              Resolved: