Hello,
I’ve written a function with aggregation in Realm and am getting an output that looks like this:
[
{
"_id": {
"carId": "5e90838738eff556f0fa48d0",
"carMake": "BMW"
},
"count": {
"$numberLong": "2"
}
}
]
I’m trying to get
[
{
car: { "carId": "5e90838738eff556f0fa48d0", "carMake": "BMW" },
count: 2
}
]
I am not sure if by default Real return EJSON so
I tried EJSON.parse(summary) and get an error.
Any idea how to format the aggregation?
here is a snippet of the function
const summary = cars.aggregate([
{ $match: { accountId: accountId } },
{ $group : { _id:{carId:"$carId", carMake:"$carMake"},
count: {"$sum":1}}}
])
return summary;