I have the following collection
{
"_id": "12345",
"Products": [
"Product1",
"Product2"
],
"State": "active",
}
And would like to project it similar to the output below
_id: "12345"
Products: "Product1, product2"
I tried this but im not getting the desired output of a comman seperated concatenated string
{
_id: 1,
Products: {
$reduce: {
input: "$Products",
initialValue:"0" ,
in: {concat: ["$$value", "$$this"] }
}
}
}
Productsis. Is it an array of objects soProducts: [{ '0': 'Product1'}, { '1': 'product2'}]or is it an array of just strings soProducts: ['Product1', 'product2']? It would help if you post an actual sample document.$condis needed becuase you don't want a leading or a trailing comma in the output I assume.