1. Index:
Indexing is time-consuming and laborious, and requires a lot of resource consumption. Use the {"Bakckground": true} option to make the process complete in the background while processing the request normally. If you do not include background
This option, the database blocks all requests that are established during indexing. Blocking practices can make the index faster, and it also means that the app cannot answer during this time. Even in the background it can have some effect on normal operation.
2. Geo-Spatial Index:
The popular word is to find the nearest n places from the current location. By default, the extent of the geospatial index assumption value is -180~180. If you want to use a different value, you can specify the maximum minimum value by using the Ensureindex option:
>db.star.trek.ensureindex ({"Light-years": "2d"},{"min": -1000, "Max": 1000});
This creates a spatial index of 2000 light-years.
For the "$near" example, here's a list:
>db.map.find ({"GPs": {"$near": [40,-73]}}). Limit (10)
You can also use Geonear.
>db.runcommand ({geonear: "Map", near:[40,-70],num:10});
Geonear returns the distance from each document to the query point. This distance is measured in the data you insert, and if you insert it at a latitude angle, the distance is the latitude and longitude.
You can also specify a document within a shape.
For example $center to find all the sites inside the circle
>db.map.find ({"GPs": {"$within": {"$center": [12,34],5]}});
3. MONGO's geo-spatial index assumes that the index content is on a flat surface. This means that for spheres, such as the Earth, it is not very precise, especially in polar regions. In particular, the length of the parallels between the two meridians is not the same in the equator and in the Yukon Territory, which is much shorter.
MongoDB Geo-Spatial index