In order to perform geospatial searches, we first need to prepare the database by creating the necessary geospatial fields from our existing latitude and longitude information. We then need to define an index on the newly added field.
Creating a new field from existing ones is another opportunity to use the aggregation framework. In earlier versions of MongoDB, it was necessary to create a JavaScript function that looped through the database collection and updated each document individually. As you can imagine, this sort of operation was enormously expensive in terms of time and resources needed. Essentially, two commands had to be performed for every document: a query followed by an update.
As the name implies, the flat 2D MongoDB geospatial model is used for situations where a street map is appropriate. This model is perfect for giving directions to properties, or for locating stores within a certain geographic area, and so forth.