Docs Menu
Docs Home
/
IntelliJ Plugin

Index Performance Warnings

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.

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:

Index warning in the IntelliJ Plugin.

To create an index for the query:

1

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 })
2

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})
  • Disable Warnings

  • Indexes

  • Operational Factors and Data Models

Back

Type Validation

On this page