I am trying to concat some nested documents inside an array using MongoDB shell:
What I have
"id": 1,
"instructions": [
{"text": "A"},
{"text": "B"},
{"text": "C"}
]
What I want to obtain
"id" : 1
"instructions": "ABC"
What I have tried
{
$project: {
"instructions": {
$reduce: {
input: "$instructions.text",
initialValue: [],
in: {
$concat : ["$$value", "$$this"]
}
}
}
}
}
What I obtain
$concat only supports strings, not array