Spherical indexes and GeoJSON compliant data in Mongo
Before we continue with this recipe, we need to look at the previous recipe Flat plane 2D geospatial queries in Mongo using geospatial indexes to get an understanding of what geospatial indexes are in MongoDB and how to use the 2D indexes. So far, we have imported the JSON documents in a non-standard format in MongoDB collection, created geospatial indexes, and queried them it. This approach works perfectly fine and in fact, it was the only option available until MongoDB 2.4. version 2.4 of MongoDB supports an additional way to store, index, and query the documents in the collections. There is a standard way to represent geospatial data particularly meant for geodata exchange in JSON and the specification of GeoJSON mentions it in detail in the following link: http://geojson.org/geojson-spec.html. We can now store the data in this format.
There are various geographic figure types supported by this specification. However, for our use case...