[SERVER-27484] allow $setUnion in $group Created: 21/Dec/16  Updated: 06/Dec/22  Resolved: 23/Jan/17

Status: Closed
Project: Core Server
Component/s: Aggregation Framework
Affects Version/s: None
Fix Version/s: None

Type: Improvement Priority: Minor - P4
Reporter: tony kerz Assignee: Backlog - Query Team (Inactive)
Resolution: Duplicate Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Duplicate
duplicates SERVER-16284 Allow for $pushall / $push with $each... Open
Related
is related to SERVER-27644 distinct on a view doesn't "flatten" ... Closed
Assigned Teams:
Query
Participants:

 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.



 Comments   
Comment by David Storch [ 23/Jan/17 ]

Hi tony-kerz,

This request looks very similar to SERVER-16284, so I'm resolving as a duplicate. Please review that ticket and watch for updates.

Best,
Dave

Comment by Kelsey Schubert [ 21/Dec/16 ]

Hi tony-kerz,

Thank you for the improvement request. I've marked this ticket to be considered by the Query Team. Please continue to watch for updates.

Kind regards,
Thomas

Generated at Thu Feb 08 04:15:17 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.