This page describes the types of indexes you can create in MongoDB. Different index types support different types of data and queries.
Single Field Index
Single field indexes collect and sort data from a single field in each document in a collection.
This image shows an index on a single field, score:
To learn more, see Single Field Indexes.
Compound Index
Compound indexes collect and sort data from multiple field values from each document in a collection. You can use the compound index to query the first field or any prefix fields of the index. The order of fields in a compound index is very important. The B-tree created by a compound index stores the sorted data in the order that the index specifies the fields.
For example, the following image shows a compound index where documents
are first sorted by userid in ascending order (alphabetically).
Then, the scores for each userid are sorted in descending order:
To learn more, see Compound Indexes.
Multikey Index
Multikey indexes collect and sort data stored in arrays.
This image shows a multikey index on the addr.zip field:
To learn more, see Multikey Indexes.
Geospatial Index
Geospatial indexes improve performance for queries on geospatial coordinate data. To learn more, see Geospatial Indexes.
Hashed Index
Hashed indexes support hashed sharding. Hashed indexes index the hash of a field's value.
To learn more, see Hashed Indexes.
Text Index
Text indexes support text search queries on fields containing string content.
To learn more, see Text Indexes on Self-Managed Deployments.
Note
Use MongoDB Search or Vector Search
MongoDB also offers the following text search solutions:
MongoDB Search provides improved performance and functionality compared to on-premises text search.
Vector Search provides vector search capabilities to perform semantic, hybrid, and generative search.
Clustered Index
Clustered indexes specify the order in which clustered collections store data. Collections created with a clustered index are called clustered collections.
To learn how to create a collection with a clustered index, see Date Clustered Index Key Example.