Docs Menu
Docs Home
/
MongoDB for IntelliJ Plugin

Database Reference Validation

On this page

  • Non-existent Field Name
  • Non-existent Collection Name
  • Non-existent Database Name
  • Example
  • Learn More

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:

Field <fieldName> does not exist in collection <collectionName>.

If you reference a collection name that doesn't exist in the database, the IntelliJ Plugin raises the following warning:

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

If you reference a database that doesn't exist in the data source, the IntelliJ Plugin raises the following warning:

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

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

  • Type Validation

Back

Autocomplete