Before conducting a geospatial query, you need to create a 2DÂ index on this field. Here is the command we use to create a flat 2D index on the newly created geospatial field:
db.world_cities.createIndex( { "geo_spatial_flat" : "2d" } );
Here is a screenshot of this operation:
It is not recommended to create geoHayStackindex (https://docs.mongodb.com/manual/core/geohaystack/#geohaystack-indexes) as this is deprecated in MongoDB 4.4. It's also worth noting that the geoSearch database command (https://docs.mongodb.com/master/reference/command/geoSearch/#geosearch) has also been deprecated in MongoDB 4.4.
Before we examine the spherical model, it's important to discuss GeoJSON objects.