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