Suppose I have two documents in a collection:
[
{
"_id": 0,
"name": "aaaa",
"phone": 111
},
{
"_id": 1,
"name": "bbbb",
"phone": 999
}
]
I want to run an aggregation pipeline that will merge/wrap/combine ALL the fields into a top-level root object called lead
. Without mentioning/hardcoding the field names in the query.
Expected output:
[
{
"lead": {
"_id": 0,
"name": "aaaa",
"phone": 111
}
},
{
"lead": {
"_id": 1,
"name": "bbbb",
"phone": 999
}
}
]