MongoDB Geo-Spatial index

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.