I have utilized Mongodb aggregation and used the $facet operator to count each value of "reli" and "prov" from the collection.
Here is the code I used to retrieve results from the database:
const keyy = await db.aggregate([
$facet: { "reli": [
{ $group: { _id: '$reli', count: { $sum: 1 } } } ],
"prov": [
{ $group: { _id: '$prov', count: { $sum: 1 } } }
],
])
The output appears as follows:
[
{
"reli": [
{
"_id": "abcdef",
"count": 6
},
{
"_id": "ghij",
"count": 1
},
],
"prov": [
{
"_id": "hello",
"count": 63
},
{
"_id": "hey",
"count": 9
},
]
}
]
However, I desire that the expected output should be:
[
{
"reli":[
{abcdef: 6},
{ghij: 1}
],
"prov":[
{"hello": 63},
{"hey": 9}
]
}
]