Docs Menu
Docs Home
/
MongoDB Manual
/

Index Types

On this page

  • Single Field Index
  • Compound Index
  • Multikey Index
  • Geospatial Index
  • Text Index
  • Hashed Index
  • Clustered Index

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 two or more fields in each document in a collection. Data is grouped by the first field in the index and then by each subsequent field.

For example, the following image shows a compound index where documents are first grouped 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.

You do not need to explicitly specify the multikey type. When you create an index on a field that contains an array value, MongoDB automatically sets the index to be a multikey index.

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.

MongoDB provides two types of geospatial indexes:

  • 2d indexes that use planar geometry to return results.

  • 2dsphere indexes that use spherical geometry to return results.

Text indexes support text search queries on fields containing string content.

To learn more, see Text Indexes.

Note

Use Atlas Search on Atlas Deployments

For data hosted on MongoDB Atlas, MongoDB offers a full-text search solution, Atlas Search. Atlas Search provides improved performance and functionality compared to on-premises text search.

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

To learn more, see Hashed Indexes.

New in version 5.3.

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 Clustered Collection Examples.

Back

Drop an Index

Next

Single Field Indexes