MongoDB Compound Indexes Link to heading

These indexes index multiple fields in a collection. Compound indexes are core to query optimization, and can dramatically increase read performance.

Compound indexes collect and sort data from two or more fields. Data is grouped by the first field, and then by each subsequent field.

For example, a compound index for the userId and score fields, both sorted in ascending order.

userIdscore
aa1100
ca255
ca275
ca2110
nb130
zyz90

First the index orders by userId, then score

Indexing commonly queried fields increases the likelihood of covered queries, which are queries that can be satisfied entirely using an index.

  • [[mongodb-indexes.md|Indexes]]
  • [[mongodb-esr-rule|ESR Rule]]