The spherical 2D MongoDB geospatial model is used for situations where coordinates need to be located on a sphere. An obvious example would be creating queries that provide locations on planet Earth, the moon, or other planetary bodies. Here is the command that creates a GeoJSON object from existing coordinates in the properties collection. Again, please note the use of $toDouble to convert latitude and longitude values from string to double:
db.properties.aggregate(
{ "$match": {} },
{
"$addFields": {
"address.geo_spatial":{
"type":"Point",
"coordinates":
[
{ "$toDouble" : "$address.longitude" },
{ "$toDouble" : "$address.latitude" }
]
}
}
},
{ "$out" : "properties" }
);
This...