How to convert double type in an aggregation

Hello,

I have saved some data containing numbers as a Double in mongodb. After requesting my data in Realm with an aggregation, I get my data in a format like this:

{
  "points": [
    {
      "geometry": {
        "coordinates": [
          {
            "$numberDouble": "10.1"
          },
          {
            "$numberDouble": "20.2"
          }
        ]
      }
    },
    {
      "geometry": {
        "coordinates": [
          {
            "$numberDouble": "10.1"
          },
          {
            "$numberDouble": "20.2"
          }
        ]
      }
    }
  ]
}

But I would like to get these in a JS-friedly format like this:

{
  "points": [
    {
      "geometry": {
        "coordinates": [10.1, 20.2]
      }
    },
    {
      "geometry": {
        "coordinates": [10.1, 20.2]
      }
    }
  ]
}

How can I achieve this? I’m thinking of something like this:

{
  "$set": {
    "$points.geometry.coordinates": {
      "$toDecimal": "$points.$.geometry.coordinates"
    }
  }
}

But maybe the solution is more complicated…

Thanks in advance,
Carsten

Hi,

You can use $toDouble operator:

{
  "geometry": {
    "coordinates": [
      {
        "$toDouble": "10.1"
      },
      {
        "$toDouble": "20.2"
      }
    ]
  }
}

Hi NeNaD,

thanks, but my problem is the other way round. After I requested the data from mongodb, they are not in the JS consumable format. Instead of the first output, I would like to have them in the second output format.