How to combaine all arrays into 1 array as an output

DB I have:

[
{
    item: 'notebook',
    qty: 50,
    tags: ['red', 'blank'],
    dim_cm: [14, 21]
  },
  {
    item: 'paper',
    qty: 100,
    tags: ['red', 'blank', 'plain'],
    dim_cm: [14, 21]
  },
]

I want the output to be like this:
{tags: ["red", "black", "plain"]}

My approach would be

1 $project tags array (optional but that should reduce memory needed for next stage
2 $unwind tags array
3 $group with _id:null with $addToSet accumulator

1 Like

Thanks for your help

1 Like

This topic was automatically closed 5 days after the last reply. New replies are no longer allowed.