我們試圖將一個字符串數組「連接」到聚合中的單個字符串。MongoDB Aggregation將字符串數組連接到單個字符串
鑑於是以下數據集:
類別1:
{
id: 1234,
field: 'test'
}
系列2:
{
id: 1111,
collection1_id: 1234,
name: 'Max'
},
{
id: 1112,
collection1_id: 1234,
name: 'Andy'
}
當前結果(查找等後):
{
id: 1234,
field: 'test',
collection2: ['Max', 'Andy']
}
期望的結果:
{
id: 1234,
field: 'test',
collection2: 'Max, Andy'
}
是它在某種程度上可以加入「collection2」到一個字符串?我們已經嘗試了$concat
,但它只接受字符串。
添加您到目前爲止的代碼 –