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

Array sort semantics

    XMLWordPrintable

Details

    • Bug
    • Status: Closed
    • Minor - P4
    • Resolution: Works as Designed
    • None
    • None
    • None
    • None
    • 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

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

            Dates

              Created:
              Updated:
              Resolved: