> This page location: /docs.md > /docs/development.md > /docs/manual/data-modeling.md > /docs/manual/data-modeling/schema-design-process.md

> For the complete MongoDB documentation index, see www.mongodb.com/docs/llms.txt

# Create Indexes to Support Your Queries

An index covers a query when the index contains all of the fields scanned by the query. A covered query scans the index and not the collection, which improves query performance.

Indexes can also partially support queries if a subset of the fields queried are indexed.

## About this Task

A single collection can have a maximum of 64 indexes. However, too many indexes can degrade performance before that limit is reached. For collections with a high write-to-read ratio, indexes can degrade performance because each insert must also update any indexes.

## Steps

1. Identify common queries

   To identify common query patterns in your application, use the [`$queryStats`](https://www.mongodb.com/docs/manual/reference/operator/aggregation/querystats.md#mongodb-pipeline-pipe.-queryStats) aggregation stage. `$queryStats` reports metrics for [query shapes](https://www.mongodb.com/docs/manual/reference/glossary.md#std-term-query-shape), which group queries based on shared fields.

2. Create indexes to support common queries

   After you know which fields your application frequently queries, you can create indexes to support queries on those fields. For more information, see [Examples.](https://www.mongodb.com/docs/manual/data-modeling/schema-design-process/create-indexes.md#std-label-schema-design-indexes-examples)

3. Analyze index use

   After your application begins using indexes, you can analyze your indexes' effectiveness. To see index statistics and usage, you can:

   - Use the [`$indexStats`](https://www.mongodb.com/docs/manual/reference/operator/aggregation/indexstats.md#mongodb-pipeline-pipe.-indexStats) aggregation stage.

   - For MongoDB Atlas deployments, view [Indexes](https://www.mongodb.com/docs/atlas/atlas-ui/indexes/#std-label-atlas-ui-view-indexes) in the Atlas UI.

   Consider deleting unused indexes to improve application performance. For more information, see [Remove Unnecessary Indexes.](https://www.mongodb.com/docs/manual/data-modeling/design-antipatterns/unnecessary-indexes.md#std-label-unnecessary-indexes-antipattern)

Repeat this procedure periodically to ensure that your indexes support your current workload.

## Examples

The examples on this page use data from the [sample\_mflix dataset](https://www.mongodb.com/docs/manual/sample-data/sample-mflix.md#std-label-sample-mflix). For details on how to load this dataset into your self-managed MongoDB deployment, see [Load the Sample Dataset](https://www.mongodb.com/docs/manual/sample-data/load-sample-data-local.md#std-label-sample-dataset-local). If you made any modifications to the sample databases, you may need to drop and recreate the databases to run the examples on this page.

**Note:**

Documents in the `movies` collection contain additional fields not shown here.

### Create a Single-Key Index

If your application only queries on a single key in a given collection, then you need to create a single-key index for that collection. For example, you can create an index on `title` in the `movies` collection:

```javascript
db.movies.createIndex( { title: 1 } )

```

This index supports this query:

```javascript
db.movies.find( { title: 'Mulholland Drive' } )

```

### Create a Compound Index

If your application performs queries on both a single key and multiple keys, a [compound index](https://www.mongodb.com/docs/manual/core/indexes/index-types/index-compound.md#std-label-index-type-compound) is more efficient than a single-key index. For example, you can create an index on the `year`, `runtime`, and `title` fields:

```javascript
db.movies.createIndex( { year: 1, runtime: 1, title: 1 } )

```

#### Index Prefixes

A compound index supports queries on index prefixes, which are the beginning subsets of indexed fields. For example, the preceding index supports this query:

```javascript
db.movies.find( { year: 2012, runtime: { $gt: Decimal128( "120" ) } }, { title: 1 } )

```

For more information and performance considerations on index prefixes, see [Index Prefixes.](https://www.mongodb.com/docs/manual/core/indexes/index-types/index-compound.md#std-label-compound-index-prefix)

### Create Indexes to Support `$text` Queries

For data hosted on MongoDB, you can support full-text search with MongoDB Search indexes. To learn more, see [Create a MongoDB Search Index.](https://www.mongodb.com/docs/atlas/atlas-search/create-index/)

For self-managed (non-Atlas) deployments, MongoDB provides a `text` index type that supports searching for string content in a collection. To learn more about self-managed text indexes, see [Text Indexes on Self-Managed Deployments.](https://www.mongodb.com/docs/manual/core/indexes/index-types/index-text.md#std-label-index-feature-text)

### Create Vector Search Indexes

Vector Search Indexes support queries on vector embeddings. To create Vector Search Indexes, see [Index Fields for Vector Search.](https://www.mongodb.com/docs/atlas/atlas-vector-search/vector-search-type/)

### Index Use and Collation

To use an index for string comparisons, an operation must also specify the same collation. If an operation specifies a different collation than the index specifies, the index cannot support string comparisons on the indexed fields.

**Warning:**

Collation-aware index keys might be larger than index keys for indexes without collation because indexes that are configured with collation use ICU collation keys to achieve sort order.

## Learn More

- [The ESR (Equality, Sort, Range) Guideline](https://www.mongodb.com/docs/manual/tutorial/equality-sort-range-guideline.md#std-label-esr-indexing-guideline)

- [MongoDB Collation](https://www.mongodb.com/docs/manual/reference/collation.md#std-label-collation)

- [Query Optimization](https://www.mongodb.com/docs/manual/core/query-optimization.md#std-label-read-operations-indexing)
