I would like to get the union of all the arrays in an object in MongoDB 3.4 using the aggregation framework:
This is the input:
{
_id: "001",
name: "something",
important_part: {
foo: [1,2,3],
bar: [4,5],
x: [6,7]
}
}
This should be the output:
{
_id: "001",
name: "something",
merged_arrays: [1,2,3,4,5,6,7]
}
The tricky part is, that the fields in the important_part object is dynamic, and I don't think the $setUnion operator can be used, as it needs the exact list of array fields.
Could someone please help me?
Thx in advance