Docs Menu
Docs Home
/ /

Index Types

This page describes the types of indexes you can create in MongoDB. Different index types support different types of data and queries.

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:

Diagram of an index on the ``score`` field (ascending).

To learn more, see Single Field Indexes.

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:

Diagram of a compound index on the ``userid`` field (ascending) and the ``score`` field (descending). The index sorts first by the ``userid`` field and then by the ``score`` field.

To learn more, see Compound Indexes.

Multikey indexes collect and sort data stored in arrays.

This image shows a multikey index on the addr.zip field:

Diagram of a multikey index on the ``addr.zip`` field. The ``addr`` field contains an array of address documents. The address documents contain the ``zip`` field.

To learn more, see Multikey Indexes.

Geospatial indexes improve performance for queries on geospatial coordinate data. To learn more, see Geospatial Indexes.

Hashed indexes support hashed sharding. Hashed indexes index the hash of a field's value.

To learn more, see Hashed Indexes.

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 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.

Back

Drop

On this page