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

$setUnion does not descend into nested arrays

    • Type: Icon: Bug Bug
    • Resolution: Done
    • Priority: Icon: Minor - P4 Minor - P4
    • None
    • Affects Version/s: 2.6.5
    • Component/s: Aggregation Framework
    • None
    • ALL
    • Hide

      Sample data:

      db.s.insert([{"a":1}, {"a":1}, {"a":2}, {"a":2}])
      
      db.s.aggregate([
      {$group:{"_id":"$a","s":{$push:"$a"}}},
      {$group:{"_id":null,"ds":{$push:"$s"}}},
      {$project:{"out":{$setUnion:"$ds"}}}])
      

      The expectation is:`out` to be an array [1,2]. But it does not perform any computation in these cases and returns the "ds" array as such.

      Show
      Sample data: db.s.insert([{ "a" :1}, { "a" :1}, { "a" :2}, { "a" :2}]) db.s.aggregate([ {$group:{ "_id" : "$a" , "s" :{$push: "$a" }}}, {$group:{ "_id" : null , "ds" :{$push: "$s" }}}, {$project:{ "out" :{$setUnion: "$ds" }}}]) The expectation is:`out` to be an array [1,2]. But it does not perform any computation in these cases and returns the "ds" array as such.

      The $setUnion operator doesn't work as stated in the docs. It doesn't work when its input is a variable which is an array of arrays.

            Assignee:
            Unassigned Unassigned
            Reporter:
            BatScream BatScream [X]
            Votes:
            0 Vote for this issue
            Watchers:
            5 Start watching this issue

              Created:
              Updated:
              Resolved: