Reputation: 2245
I have this aggregation result
[
{
"ids": [1,100]
},
{
"ids": [200, 100, 3]
}
]
I want to merge them as one result like this:
[
1,
200,
100,
3
]
I have tried group but the result not like I want:
{
$group: {
_id: 1,
merged: {
$push: "$ids"
}
}
}
result:
[
{
"_id": 1,
"merged": [
[1, 100],
[200, 100, 3]
]
}
]
Upvotes: 0
Views: 81
Reputation: 8705
Query
$concat
accumulator$unwind
, $group
$addToSet
$push
and $reduce
$union
aggregate(
[{"$unwind": {"path": "$ids"}},
{"$group": {"_id": null, "ids": {"$addToSet": "$ids"}}},
{"$unset": ["_id"]}])
Upvotes: 1