8.4 Indexing Reference 8.4.1 Indexing Methods in the mongo Shell MongoDB Documentation, Release 3.0.4 Name Description db.collection.createIndex() Builds an index on a collection. db.collection.dropIndex() Removes a specified index on a collection. db.collection.dropIndexes() Removes all indexes on a collection. db.collection.getIndexes() Returns an array of documents that describe the existing indexes on a collection. db.collection.getIndexStats() Renders a human-readable view of the data collected by indexStats which reflects B-tree utilization. db.collection.indexStats() Renders a human-readable view of the data collected by indexStats which reflects B-tree utilization. db.collection.reIndex() Rebuilds all existing indexes on a collection. db.collection.totalIndexSize() Reports the total size used by the indexes on a collection. Provides a wrapper around the totalIndexSize field of the collStats output. cursor.explain() Reports on the query execution plan, including index use, for a cursor. cursor.hint() Forces MongoDB to use a specific index for a query. cursor.max() Specifies an exclusive upper index bound for a cursor. For use with cursor.hint() cursor.min() Specifies an inclusive lower index bound for a cursor. For use with cursor.hint() cursor.snapshot() Forces the cursor to use the index on the _id field. Ensures that the cursor returns each document, with regards to the value of the _id field, only once. Name Description createIndexes Builds one or more indexes for a collection. dropIndexes Removes indexes from a collection. compact Defragments a collection and rebuilds the indexes. reIndex Rebuilds all indexes on a collection. validate Internal command that scans for a collection’s data and indexes for correctness. indexStats Experimental command that collects and aggregates statistics on all indexes. geoNear Performs a geospatial query that returns the documents closest to a given point. geoSearch Performs a geospatial query that uses MongoDB’s haystack index functionality. geoWalk An internal command to support geospatial queries. checkShardingIndex Internal command that validates index on shard key. Name Description $geoWithin Selects geometries within a bounding GeoJSON geometry (page 553). The 2dsphere (page 496) and 2d (page 497) indexes support $geoWithin . $geoIntersects Selects geometries that intersect with a GeoJSON geometry. The 2dsphere (page 496) index supports $geoIntersects . $near Returns geospatial objects in proximity to a point. Requires a geospatial index. The 2dsphere (page 496) and 2d (page 497) indexes support $near . $nearSphere Returns geospatial objects in proximity to a point on a sphere. Requires a geospatial index. The 2dsphere (page 496) and 2d (page 497) indexes support $nearSphere . 8.4.3 Geospatial Query Selectors 8.4.2 Indexing Database Commands Chapter 8. Indexes 552