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

Sorting on array fields works correctly when direction is descending, incorrect when ascending

    • Type: Icon: Bug Bug
    • Resolution: Done
    • Priority: Icon: Major - P3 Major - P3
    • None
    • Affects Version/s: 2.0.1, 2.0.2
    • Component/s: Querying
    • Environment:
      uname -a: Linux 3.0.0-12-generic #20-Ubuntu SMP Fri Oct 7 14:56:25 UTC 2011 x86_64 x86_64 x86_64 GNU/Linux
    • Linux

      sorting by

      {array : 1}

      does not appear to do anything, it returns the same results as just running find(). This issue does not appear to exist in 1.8.4

      > db.things.insert({ array: [ [0, ""], [3, "3"] ] })
      > db.things.insert({ array: [ [0, ""], [1, "1"] ] })
      > db.things.insert({ array: [ [0, ""], [4, "4"] ] })
      > db.things.insert({ array: [ [0, ""], [5, "5"] ] })
      > db.things.insert({ array: [ [0, ""], [2, "2"] ] })
      > db.things.find()
      { "_id" : ObjectId("4ecb2dbc0ac2d0b3fe518048"), "array" : [ [ 0, "" ], [ 3, "3" ] ] }
      { "_id" : ObjectId("4ecb2dc20ac2d0b3fe518049"), "array" : [ [ 0, "" ], [ 1, "1" ] ] }
      { "_id" : ObjectId("4ecb2dc70ac2d0b3fe51804a"), "array" : [ [ 0, "" ], [ 4, "4" ] ] }
      { "_id" : ObjectId("4ecb2dcb0ac2d0b3fe51804b"), "array" : [ [ 0, "" ], [ 5, "5" ] ] }
      { "_id" : ObjectId("4ecb2dcf0ac2d0b3fe51804c"), "array" : [ [ 0, "" ], [ 2, "2" ] ] }
      > db.things.find().sort({ array: 1 })
      { "_id" : ObjectId("4ecb2dbc0ac2d0b3fe518048"), "array" : [ [ 0, "" ], [ 3, "3" ] ] }
      { "_id" : ObjectId("4ecb2dc20ac2d0b3fe518049"), "array" : [ [ 0, "" ], [ 1, "1" ] ] }
      { "_id" : ObjectId("4ecb2dc70ac2d0b3fe51804a"), "array" : [ [ 0, "" ], [ 4, "4" ] ] }
      { "_id" : ObjectId("4ecb2dcb0ac2d0b3fe51804b"), "array" : [ [ 0, "" ], [ 5, "5" ] ] }
      { "_id" : ObjectId("4ecb2dcf0ac2d0b3fe51804c"), "array" : [ [ 0, "" ], [ 2, "2" ] ] }
      > db.things.find().sort({ array: -1 })
      { "_id" : ObjectId("4ecb2dcb0ac2d0b3fe51804b"), "array" : [ [ 0, "" ], [ 5, "5" ] ] }
      { "_id" : ObjectId("4ecb2dc70ac2d0b3fe51804a"), "array" : [ [ 0, "" ], [ 4, "4" ] ] }
      { "_id" : ObjectId("4ecb2dbc0ac2d0b3fe518048"), "array" : [ [ 0, "" ], [ 3, "3" ] ] }
      { "_id" : ObjectId("4ecb2dcf0ac2d0b3fe51804c"), "array" : [ [ 0, "" ], [ 2, "2" ] ] }
      { "_id" : ObjectId("4ecb2dc20ac2d0b3fe518049"), "array" : [ [ 0, "" ], [ 1, "1" ] ] }
      

            Assignee:
            aaron Aaron Staple
            Reporter:
            re5et atom smith
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: