MongoDB Documentation, Release 3.0.4 You cannot use a 2d index as a shard key when sharding a collection. However, you can create and maintain a geospatial index on a sharded collection by using a different field as the shard key. Behavior The 2d index supports calculations on a flat, Euclidean plane. The 2d index also supports distance-only calculations on a sphere, but for geometric calculations (e.g. $geoWithin ) on a sphere, store data as GeoJSON objects and use the 2dsphere index type. A 2d index can reference two fields. The first must be the location field. A 2d compound index constructs queries that select first on the location field, and then filters those results by the additional criteria. A compound 2d index can cover queries. Points on a 2D Plane To store location data as legacy coordinate pairs, use an array or an embedded document. When possible, use the array format: Consider the embedded document form: loc : [ <longitude> , <latitude> ] loc : { lng : <longitude> , lat : <latitude> } Arrays are preferred as certain languages do not guarantee associative map ordering. For all points, if you use longitude and latitude, store coordinates in longitude, latitude order. sparse Property 2d indexes are sparse (page 505) by default and ignores the sparse: true (page 505) option. If a document lacks a 2d index field (or the field is null or an empty array), MongoDB does not add an entry for the document to the 2d index. For inserts, MongoDB inserts the document but does not add to the 2d index. For a compound index that includes a 2d index key along with keys of other types, only the 2d index field determines whether the index references a document. geoHaystack Indexes A geoHaystack index is a special index that is optimized to return results over small areas. geoHaystack indexes improve performance on queries that use flat geometry. For queries that use spherical geometry, a 2dsphere index is a better option than a haystack index. 2dsphere in- dexes (page 496) allow field reordering; geoHaystack indexes require the first field to be the location field. Also, geoHaystack indexes are only usable via commands and so always return all results at once. Behavior geoHaystack indexes create “buckets” of documents from the same geographic area in order to improve performance for queries limited to that area. Each bucket in a geoHaystack index contains all the documents within a specified proximity to a given longitude and latitude. sparse Property geoHaystack indexes are sparse (page 505) by default and ignore the sparse: true (page 505) option. If a document lacks a geoHaystack index field (or the field is null or an empty array), MongoDB does not add an entry for the document to the geoHaystack index. For inserts, MongoDB inserts the document but does not add to the geoHaystack index. geoHaystack indexes include one geoHaystack index key and one non-geospatial index key; however, only the geoHaystack index field determines whether the index references a document. Create geoHaystack Index To create a geoHaystack index, see Create a Haystack Index (page 536). For information and example on querying a haystack index, see Query a Haystack Index (page 536). Chapter 8. Indexes 498