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

allow $setUnion in $group

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

      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-server-query Backlog - Query Team (Inactive)
            Reporter:
            tony-kerz tony kerz
            Votes:
            0 Vote for this issue
            Watchers:
            7 Start watching this issue

              Created:
              Updated:
              Resolved: