MongoDB Documentation, Release 3.0.4 In the following example, the find() operation will return an exact match on a location if you have a { ’loc’: 1} index: This query will return any documents with the value of [ <x> , <y> ] . A haystack index must reference two fields: the location field and a second field. The second field is used for exact matches. Haystack indexes return documents based on location and an exact match on a single additional criterion. These indexes are not necessarily suited to returning the closest documents to a particular location. To build a haystack index, use the following syntax: To build a haystack index, you must specify the bucketSize option when creating the index. A bucketSize of 5 creates an index that groups location values that are within 5 units of the specified longitude and latitude. The bucketSize also determines the granularity of the index. You can tune the parameter to the distribution of your data so that in general you search only very small regions. The areas defined by buckets can overlap. A document can exist in multiple buckets. If you have a collection with documents that contain fields similar to the following: The following operations create a haystack index with buckets that store keys within 1 unit of longitude or latitude. This index stores the document with an _id field that has the value 200 in two different buckets: To query using a haystack index you use the geoSearch command. See Query a Haystack Index (page 536). By default, queries that use a haystack index return 50 documents. A haystack index is a special 2d geospatial index that is optimized to return results over small areas. To create a haystack index see Create a Haystack Index (page 536). To query a haystack index, use the geoSearch command. You must specify both the coordinates and the additional field to geoSearch . For example, to return all documents with the value restaurant in the type field near the example point, the command would resemble: Chapter 8. Indexes 536 Query a Haystack Index • In a bucket that includes the document where the _id field has a value of 100 • In a bucket that includes the document where the _id field has a value of 300 Example db.coll.createIndex( { <location field> : "geoHaystack" , <additional field> : 1 } , { bucketSize : <bucket value> } ) { _id : 100, pos: { lng : 126.9, lat : 35.2 } , type : "restaurant"} { _id : 200, pos: { lng : 127.5, lat : 36.1 } , type : "restaurant"} { _id : 300, pos: { lng : 128.0, lat : 36.7 } , type : "national park"} Create a Haystack Index db.<collection>.find( { loc: [ <x> , <y> ] } ) db.places.createIndex( { pos : "geoHaystack", type : 1 } , { bucketSize : 1 } )