-2
skatespot-dev> db.parks.findOne();
{
  _id: ObjectId("638f9866d9014fabfc47275e"),
  address: '801 Pine St, Anchorage, AK',
  name: 'Russian Jack Skatepark',
  location: { type: 'Point', coordinates: [ '61.214855', '-149.793563' ] }
}

I need to run a query to convert all coodinates to floats i guess.

chovy
  • 72,281
  • 52
  • 227
  • 295
  • This is looks like a duplicate of [this question](https://stackoverflow.com/questions/37942844/mongodb-convert-string-type-to-float-type) – justin Dec 07 '22 at 16:46

1 Answers1

1

You can convert them to double using update with pipeline, like this:

db.collection.updateMany({},
[
  {
    $set: {
      "location.coordinates": [
        {
          $toDouble: {
            $first: "$location.coordinates"
          }
        },
        {
          $toDouble: {
            $last: "$location.coordinates"
          }
        }
      ]
    }
  }
])

See how it works on the playground example

nimrod serok
  • 14,151
  • 2
  • 11
  • 33