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

$bucketAuto $concatArrays does not preserve order

    • Type: Icon: Bug Bug
    • Resolution: Fixed
    • Priority: Icon: Minor - P4 Minor - P4
    • 8.1.0-rc0
    • Affects Version/s: None
    • Component/s: None
    • None
    • Query Optimization
    • Fully Compatible
    • ALL

      The $concatArrays accumulator (added as part of SERVER-16284) suffers from the same issue as SERVER-90597, so it needs a similar fix

      db.test.find()
      { "_id" : 0, "n" : 3, "arr" : [ 0 ] }
      { "_id" : 1, "n" : 2, "arr" : [ 1 ] }
      { "_id" : 2, "n" : 1, "arr" : [ 2 ] }
      { "_id" : 3, "n" : 0, "arr" : [ 3 ] }
      
      db.test.aggregate([{$sort: {_id: 1}}, {$bucketAuto: {groupBy: "$n", buckets: 2, output: {foo: {$concatArrays: "$arr"}}}}])
      { "_id" : { "min" : 0, "max" : 2 }, "foo" : [ 3, 2 ] }
      { "_id" : { "min" : 2, "max" : 3 }, "foo" : [ 1, 0 ] } 

      The order of the elements in the foo arrays should be swapped since the incoming document order is such that the values put into the foo array are increasing.

            Assignee:
            militsa.sotirova@mongodb.com Militsa Sotirova
            Reporter:
            militsa.sotirova@mongodb.com Militsa Sotirova
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated:
              Resolved: