Definition
The MongoDB for IntelliJ Plugin examines if application queries use indexes. If a query doesn't use an index or is only partially covered by an index, the plugin displays a warning for that query.
To resolve the warning, consider creating an index for the query.
Before you add an index, consider if:
The query runs often enough to justify reducing the write performance for faster reads.
You can change the query to use an existing index.
You can also disable index warnings.
For more information about indexes, see Indexes.
Examples
In the following example Java code snippet, the awards
document field is used in a query, but the field isn't indexed in the database:
client.getDatabase( "sample_mflix" ).getCollection( "movies" ).find( Filters.ne( "awards", "Comedy" ) )
The side panel shows the following warning under Performance Warnings:

Create an Index
To create an index for the query:
Click the Create an Index button displayed in the side panel warning.
The plugin displays the Database Explorer Playgrounds screen with template code for creating an index:
// region Queries covered by this index // alt.mongodb.javadriver.JavaDriverRepository#getRatings at line 32 // endregion // Learn about creating an index: https://www.mongodb.com/docs/v7.0/core/data-model-operations/#indexes db.getSiblingDB("sample_mflix").getCollection("movies") .createIndex({ "awards": 1 })
Create an index on the awards field.
Set <your_field_1>
to awards
in the example code and then run the createIndex()
method in the Database Explorer Playgrounds screen. For example:
db.getSiblingDB("sample_database").getCollection("movies"). createIndex({"awards": 1})