Indexing Reference
On this page
MongoDB 5.0 is end of life as of October 2024. This version of the documentation is no longer
supported. To upgrade your 5.0 deployment, see the MongoDB 6.0 upgrade procedures.
Indexing Methods in mongosh
Name | Description |
---|---|
Builds an index on a collection. | |
Removes a specified index on a collection. | |
Removes all indexes on a collection. | |
Returns an array of documents that describe the existing indexes on a collection. | |
Rebuilds all existing indexes on a collection. | |
Reports the total size used by the indexes on a collection. Provides a wrapper around the totalIndexSize field of the collStats output. | |
Reports on the query execution plan for a cursor. | |
Forces MongoDB to use a specific index for a query. | |
Specifies an exclusive upper index bound for a cursor. For use with cursor.hint() | |
Specifies an inclusive lower index bound for a cursor. For use with cursor.hint() |
Indexing Database Commands
Name | Description |
---|---|
Builds one or more indexes for a collection. | |
Removes indexes from a collection. | |
Defragments a collection and rebuilds the indexes. | |
Rebuilds all indexes on a collection. | |
Internal command that scans for a collection's data and indexes for correctness. | |
Removed in MongoDB 5.0. Performs a geospatial query that uses
MongoDB's haystack index functionality. | |
Changes the minimum number of data-bearing members (i.e commit
quorum), including the primary, that must vote to commit an
in-progress index build before the primary marks
those indexes as ready. |
Geospatial Query Selectors
Name | Description |
---|---|
Selects geometries within a bounding GeoJSON geometry. The 2dsphere and 2d indexes support
$geoWithin . | |
Selects geometries that intersect with a GeoJSON geometry.
The 2dsphere index supports
$geoIntersects . | |
Returns geospatial objects in proximity to a point on a sphere.
Requires a geospatial index. The 2dsphere and 2d indexes support
$nearSphere . |
Indexing Query Modifiers
Name | Description |
---|---|
Forces MongoDB to report on query execution plans. See explain() . | |
Forces MongoDB to use a specific index. See hint() | |
Specifies an exclusive upper limit for the index to use in a query. See max() . | |
Specifies an inclusive lower limit for the index to use in a query. See min() . | |
Forces the cursor to only return fields included in the index. |