I'm working with mongodb and I'm dealing with aggregate to join two collections, now I would like to convert my result
"Users" : [
[
"Carl",
"John",
"Ever"
],
[
"Dani",
"GG",
"Sussan"
],
.... N arrays
]
to this output
"Users" : [
"Carl",
"John",
"Ever",
"Dani",
"GG",
"Sussan",
..... M elements from N arrays
]
CodePudding user response:
Query
- reduce starting from
[]
- concat each array member to one flatten array
aggregate(
[{"$set":
{"Users":
{"$reduce":
{"input":"$Users",
"initialValue":[],
"in":{"$concatArrays":["$$value", "$$this"]}}}}}])