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

allow $setUnion in $group

    XMLWordPrintable

Details

    • Improvement
    • Status: Closed
    • Minor - P4
    • Resolution: Duplicate
    • None
    • None
    • Aggregation Framework
    • None

    Description

      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.

      Attachments

        Issue Links

          Activity

            People

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

              Dates

                Created:
                Updated:
                Resolved: