-
Type: Improvement
-
Resolution: Duplicate
-
Priority: 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.
- duplicates
-
SERVER-16284 Allow for $pushall / $push with $each to allow pushing all elements of array in $group
- Closed
- is related to
-
SERVER-27644 distinct on a view doesn't "flatten" array members
- Closed