Definition
The MongoDB for IntelliJ Plugin enables you to run queries written in Java directly in the Database Explorer Playgrounds.
The Run icon appears next to your MongoDB queries.

Behavior
When you click the Run icon, the plugin automatically converts your Java query to mongosh
syntax and opens a Playground file with the populated query.
For field values that are variables determined at runtime, the plugin creates a placeholder variable. You can populate this placeholder with a test value and run the query in the Playground.
Limitations
The IntelliJ Plugin does not generate insights in the side panel for the following Java and Spring queries:
Any query or aggregation that does not use a BSON builder exposed by the MongoDB Java Driver. This includes parts of queries and aggregations written using the following constructors:
Documents
BasicDBObjects
BasicDBLists
BasicDBObjectBuilders
Queries that use unsupported BSON builder methods provided by the MongoDB Java Driver. For a list of Java Driver methods that can be used for generating insights by the IntelliJ Plugin, see Java Driver Methods to Generate Insights.
Queries that use unsupported methods provided by Spring Data MongoDB. For a list of Spring Data methods that can be used for generating insights by the IntelliJ Plugin, see Spring Criteria Methods to Generate Insights.
Example
In this example, the Java query on the production.trips
collection resembles the following:
public List<Document> findCompletedTripsByDriver(String driverId) { return trips.find(Filters.and( Filters.eq(fieldName: "trip_status", value: "completed"), Filters.eq(fieldName: "driver_id", driverId) )).into(new ArrayList<>()); }
The following code example shows the converted query from the Java code above:
var driver_id = "<driver ID>" db.getSiblingsDB("production") .getCollection("trips") .find({ "$and" : [ { "trip_status" : "completed" }, { "driver_id" : driver_id } ], })
In this example, driver_id
is a variable that holds a value determined at runtime. In order to test that your query outputs the results you expect, you must specify a test value by replacing <driver ID>
with the driver ID. For example, driver_id = "1a2b3c4d5e"
.
Once you are satisfied with the query, you can run it in the Playground and view the query results.
