allow $setUnion in $group

XMLWordPrintableJSON

    • Type: Improvement
    • Resolution: Duplicate
    • Priority: Minor - P4
    • None
    • Affects Version/s: None
    • Component/s: Aggregation Framework
    • None
    • Query
    • None
    • 3
    • None
    • None
    • None
    • None
    • None
    • None

      i have a situation where i have arrays in collection documents that i want to aggregate into a "union" array on a result, something like:

      {key: 1, numbers: [1, 2, 3]}
      {key: 1, numbers: [2, 3, 4]}
      

      and i would like to do something like:

      aggregate(
        [
          {$group: {_id: '$key', numbers: {$setUnion: '$numbers'}}}
        ]
      )
      

      and have the result be:

      {_id: 1, numbers: [1, 2, 3, 4]}
      

      right now i would have to {$unwind: '$numbers'}
      first and then use {$addToSet: '$numbers'} which is more steps, and seems like it could add significant overhead with high volume arrays and bulkier documents.

            Assignee:
            Backlog - Query Team (Inactive)
            Reporter:
            tony kerz
            Votes:
            0 Vote for this issue
            Watchers:
            7 Start watching this issue

              Created:
              Updated:
              Resolved: