In Mongo 3.4+ kun je $reduce
. gebruiken om 2D-arrays af te vlakken.
db.collection.aggregate(
[
{
$project: {
"countries": {
$reduce: {
input: '$Countries',
initialValue: [],
in: {$concatArrays: ['$$value', '$$this']}
}
}
}
}
]
)
Documenten:https://docs.mongodb.com/manual/reference/ operator/aggregatie/verminderen/