Manage Indexes in Data Explorer¶
You can use the Data Explorer to manage indexes on your collections.
Indexes support the efficient execution of queries in MongoDB and should be considered for fields which your application reads often. To learn more about creating effective indexes, see Indexing Strategies.
To access the Data Explorer:
- Click Databases in the top-left corner of Atlas.
- Click Browse Collections for your desired database deployment.
Or, if you are already viewing a specific database deployment, select the Collections tab.
Required Roles¶
To create or drop indexes, you must have access provided by at least one of the following roles:
View Indexes¶
From the Collections tab, you can view index information for a collection. To view index information for a collection:
Select the database for the collection.¶
The main panel and Namespaces on the left side list the collections in the database.
Select the collection on the left-hand side or in the main panel.¶
The main panel displays the Find, Indexes, and Aggregation views.
Select the Indexes view.¶
The indexes table lists the indexes and associated index information for the collection. Index information includes the index definition, the size, and the usage frequency.
Create an Index¶
When you create indexes, keep the ratio of reads to writes on the target collection in mind. Indexes come with a performance cost, but are more than worth the cost for frequent queries on large data sets. Before you create an index, review the documented indexing strategies.
You can build full-text search with Atlas Search. Atlas Search offers fine-grained text indexing. To learn more, see Define Atlas Search Indexes.
To create an index for a collection through the Data Explorer:
Click the Indexes tab.¶
Select the collection you wish to index, and go to the Indexes tab.
Click Create Index.¶
In the Create Index modal, enter the index key specification document:
{ <field1>: <index type>, ... }
To create a compound index on the fields category
(ascending order) and score
(descending order), specify the
index specification document:
{ category: 1, score: -1 }
To learn more about indexes, see Indexes.
(Optional) Specify the index options.¶
When you create an index, you can specify a variety of index options.
Examples:
- For partial indexes, specify the partialFilterExpression option.
- For sparse indexes, specify the sparse option.
- For TTL indexes, specify the expireAfterSeconds option.
- For 2d Indexes, specify the options for 2d Indexes
{ <option1>: <value1>, ... }
The following options document specifies the unique
option and
the name
for the index:
{ unique: true, name: "myUniqueIndex" }
You cannot perform a rolling build for a unique index. If you
enable building indexes in a rolling fashion with the
unique
index option, Atlas rejects your configuration
with an error message.
(Optional) Set the Collation options.¶
Use collation to specify language-specific rules for string comparison,
such as rules for lettercase and accent marks. The
collation document
contains a locale
field which indicates the ICU Locale code, and may contain other
fields to define collation behavior.
The following collation option document specifies a locale value
of fr
for a French language collation:
{ "locale": "fr" }
To review the list of locales that MongoDB collation supports, see the list of languages and locales. To learn more about collation options, including which are enabled by default for each locale, see Collation in the MongoDB manual.
(Optional) Enable building indexes in a rolling fashion.¶
Rolling index builds succeed only when they meet certain conditions. To ensure your index build succeeds, avoid the following design patterns that commonly trigger a restart loop:
- Index key exceeds the index key limit
- Index name already exists
- Index on more than one array field
- Index on collection that has the maximum number of text indexes
- Text index on collection that has the maximum number of text indexes
Data Explorer does not support building indexes with a rolling build
for M0
free clusters and M2/M5
shared clusters. You
can't build indexes with a rolling build for
serverless instances.
Building indexes in a rolling fashion reduces the performance impact of building indexes on replica sets and sharded clusters.
To maintain cluster availability:
- Atlas removes one node from the cluster at a time starting with a secondary.
- More than one node can go down at a time, but Atlas always keeps a majority of the nodes online.
To learn more about rebuilding indexes, see Build Indexes on Replica Sets.
The following index options are incompatible with building indexes in a rolling fashion:
If you specify any of these options in the Options pane, Atlas rejects your configuration with an error message.
Click Create.¶
In the Confirm Operation modal, confirm your index.¶
Drop an Index¶
To drop an index from a collection through the Data Explorer:
Go to the Indexes tab.¶
Select the collection whose index you wish to drop, and go to the Indexes tab.
Click the Drop Index button for the index to drop.¶
Confirm action.¶
Confirm by typing the name of the index, and click Drop.
You cannot delete the _id
index.