Docs Menu
Docs Home
/
IntelliJ Plugin

Database Reference Validation

The MongoDB for IntelliJ Plugin validates database references in your Java driver or Spring Criteria code to ensure that the specified database, collection, or field exists in the server.

If you reference a field, collection, or database name that isn't in your data source, the plugin shows a warning that indicates the reference doesn't exist.

To resolve the warning:

  • Ensure that you're connected to the correct data source in the Connections Toolbar.

  • Check that you're referencing the correct database and collection in your code.

  • Verify that your database or collection contains the field you are trying to reference.

If you reference a field name that doesn't exist in the collection, the IntelliJ Plugin raises the following warning in the side panel under Correctness Warnings:

Field <fieldName> does not seem to exist in collection.

If you reference a collection name that doesn't exist in the database, the IntelliJ Plugin raises the following warning in the side panel under Environment Mismatch Warnings:

Cannot resolve <collectionName> collection in <dbName> database in the
connected data source.

To resolve the warning, ensure that the referenced collection exists in your database. Alternatively, you can click Choose a connection in the side panel to select a different data source that contains the referenced collection.

If you reference a database that doesn't exist in the data source, the IntelliJ Plugin raises the following warning in the side panel under Environment Mismatch Warnings:

Cannot resolve <dbName> database reference in the connected data source.

To resolve the warning, ensure that the referenced database exists in your deployment. Alternatively, you can click Choose a connection in the side panel to select a different data source that contains the referenced database.

The following example references the sample_mflix database, which contains data on movies and movie theaters, from the Atlas sample datasets.

The sample code attempts to call a restaurant_name collection:

public List<Document> getHundredYearOldMovies() {
return client.getDatabase("sample_mflix")
.getCollection("restaurant_name")
.find(Filters.eq("year", 1924))
.into(new ArrayList<>());
}

Because the collection doesn't exist in the sample_mflix database, the IntelliJ Plugin raises a warning that the collection cannot be resolved:

Cannot resolve "restaurant_name" collection in "sample_mflix" database in the
connected data source.``

To resolve the warning, reference a collection that exists in the sample_mflix database:

public List<Document> getHundredYearOldMovies() {
return client.getDatabase("sample_mflix")
.getCollection("movies")
.find(Filters.eq("year", 1924))
.into(new ArrayList<>());
}
  • Connect to Your MongoDB Deployment

  • Autocomplete

  • Disable Warnings

  • Type Validation

Back

Autocomplete

On this page