We're trying to 'join' an array of strings to a single string within an aggregation.
Given is the following dataset:
Collection 1:
{
id: 1234,
field: 'test'
}
Collection 2:
{
id: 1111,
collection1_id: 1234,
name: 'Max'
},
{
id: 1112,
collection1_id: 1234,
name: 'Andy'
}
The current result (after lookup etc.):
{
id: 1234,
field: 'test',
collection2: ['Max', 'Andy']
}
The desired result:
{
id: 1234,
field: 'test',
collection2: 'Max, Andy'
}
Is it somehow possible to join the 'collection2' to a single string? We've tried with $concat
but it only accepts strings.
$reduce
– Kosygin