Realm function JSON ouput

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;

Hi Herb
I have the same issue while running the function.
As per my understanding “return” always modifies the object to EJOSN format.

You can see the actual result by console.log after parsing instead of “return”

Thanks for the reply Amiya.
Indeed, JSON.stringify(summary) is what I had to do to correct the issue.