MongoDB Indexes Link to heading

Indexes are special data structures that store a small portion of the collection’s data set in an eas-to-traverse form. MongoDB indexes use a B-tree data structure.

Indexes are used to optimize queries in MongoDB. Without indexes, MongoDB has to traverse every document in a collection.

If an appropriate index exists for a query, MongoDB uses the index to reduce the number of documents it must scan.

Though indices improve read performance*, it has negative impact on write performance, since inserts must also update any indexes.

In query optimization, covered queries are queries that can be satisfied entirely using an index.

Indexes can be created as:

  • Single Field Indexes
  • [[mongodb-compound-indexes|MongoDB Compound Indexes]]
  • [[mongodb-esr-rule|MongoDB ESR Rule]]