Docs Menu
Docs Home
/
MongoDB for IntelliJ Plugin

Type Validation

On this page

  • Definition
  • Example
  • Learn More

The MongoDB for IntelliJ Plugin examines the document fields in queries to ensure that the data types match. For example, if you use a String field in an equality comparison, or an insert or update operation, the plugin examines the field value to ensure the type is also a String.

If the value type is invalid, the plugin shows a warning that indicates the type cannot be assigned.

To resolve the warning, change the field value to match the expected type. If the field is dynamically typed and strict typing rules aren't applied, you can ignore the invalid type warning.

In the following example Java code snippet, the trip_status field type is String, but the Filters operation attempts to perform an equality comparison with an Integer value 1324324:

public List<Document> findCompletedTripsByDriver( String driverId ) {
return trips.find( Filters.and(
Filters.eq( fieldName: "trip_status", value: 1324324 )
Filters.eq( fieldName: "driver_id", driverId )
)).into( new ArrayList<> () );
}

Because value is an Integer but trip_status is a String in the MongoDB documents, the plugin shows a warning about the invalid type:

"Integer" (type of provided value) can not be assigned to "String" (type of "trip_status")

To resolve the invalid type, change the value to a String. For example: "start".

  • BSON Types

  • Database Reference Validation

  • Missing Index Warning

Back

Database Reference Validation