Navigation
This version will reach end of life on Feb 2018. To upgrade, go to the Learn more about upgrading your version of MongoDB.

Geospatial Index TutorialsΒΆ

Instructions for creating and querying 2d, 2dsphere, and haystack indexes.

Find Restaurants with Geospatial Queries
Use Geospatial queries to find a user’s current neighborhood and list nearby restaurants.
Create a 2dsphere Index
A 2dsphere index supports data stored as both GeoJSON objects and as legacy coordinate pairs.
Query a 2dsphere Index
Search for locations within, near, or intersected by a GeoJSON shape, or within a circle as defined by coordinate points on a sphere.
Create a 2d Index
Create a 2d index to support queries on data stored as legacy coordinate pairs.
Query a 2d Index
Search for locations using legacy coordinate pairs.
Create a Haystack Index
A haystack index is optimized to return results over small areas. For queries that use spherical geometry, a 2dsphere index is a better option.
Query a Haystack Index
Search based on location and non-location data within a small area.
Calculate Distance Using Spherical Geometry
Convert distances to radians and back again.