## Geospatial Indexes and Queries 

MongoDB offers a number of indexes and query mechanisms to handle geospatial information. This section introduces MongoDB’s geospatial features. For complete examples of geospatial queries in MongoDB, see Geospatial Index Tutorials (page 529). 

## Surfaces 

Before storing your location data and writing queries, you must decide the type of surface to use to perform calcula- tions. The type you choose affects how you store data, what type of index to build, and the syntax of your queries. 

MongoDB offers two surface types: 

Spherical To calculate geometry over an Earth-like sphere, store your location data on a spherical surface and use 2dsphere (page 496) index. 

Store your location data as GeoJSON objects with this coordinate-axis order: longitude, latitude . The coordinate reference system for GeoJSON uses the WGS84 datum. 

Flat To calculate distances on a Euclidean plane, store your location data as legacy coordinate pairs and use a 2d (page 497) index. 

## Location Data 

If you choose spherical surface calculations, you store location data as either: 

GeoJSON Objects Queries on GeoJSON objects always calculate on a sphere. The default coordinate reference system for GeoJSON uses the WGS84 datum. 

New in version 2.4: Support for GeoJSON storage and queries is new in version 2.4. Prior to version 2.4, all geospatial data used coordinate pairs. 

Changed in version 2.6: Support for additional GeoJSON types: MultiPoint, MultiLineString, MultiPolygon, Geome- tryCollection. 

MongoDB supports the following GeoJSON objects: 

• Point 

• LineString 

• Polygon 

• MultiPoint 

• MultiLineString 

• MultiPolygon 

• GeometryCollection 

Legacy Coordinate Pairs MongoDB supports spherical surface calculations on legacy coordinate pairs using a 2dsphere index by converting the data to the GeoJSON Point type. 

If you choose flat surface calculations via a 2d index, you can store data only as legacy coordinate pairs . 

