I have data on a MongoDB collection stored in documents like these:
{
"_id": "657c54befca2b6a2cdd935ba",
"data": {
"name": "Bob",
"surname": "xxx",
"age": "20",
},
"header": {
"data": "1702646974156",
}
"_class": "Prova"
}
{
"_id": "657c54befca2b6a2cdd935bb",
"data": {
"name": "Tom",
"surname": "yyy",
"age": "25",
},
"header": {
"data": "1702646974156",
}
"_class": "Prova"
}
it is possible through query/aggregate to obtain the data already formatted in an array of objects
{
"data": [
{
"member": {
"name": "Bob",
"surname": "xxx"
}
},
{
"member": {
"name": "Tom",
"surname": "xxx"
}
}
]
}
Best regards
2
Answers
You can do this with an aggregation like so:
See HERE for a working example.
Easiest way :
See it here