Skip to content

Commit efb878d

Browse files
authored
DOCSP-45419-Run-Java-Queries (#10)
* DOCSP-45419-Run-Java-Queries * internal review * ir * xr
1 parent 179fbbf commit efb878d

File tree

5 files changed

+84
-3
lines changed

5 files changed

+84
-3
lines changed
Loading
Loading

source/index.txt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,12 +37,11 @@ The {+intellij-short+} currently supports the following features:
3737

3838
- :ref:`Autocomplete <intellij-autocomplete>` for database, collection, and
3939
document field names.
40-
4140
- :ref:`Database reference validation <intellij-db-reference-validation>`.
42-
4341
- :ref:`Type validation <intellij-type-validation>` of document fields.
44-
4542
- :ref:`Missing index warnings <intellij-index-warning>` for Java queries.
43+
- :ref:`Run Java Queries <intellij-run-java-queries>` directly in the
44+
Database Explorer Playgrounds.
4645

4746
Get Started
4847
-----------
@@ -70,5 +69,6 @@ To learn more about submitting feedback, see :ref:`intellij-submit-feedback`.
7069
Database Reference Validation </db-reference-validation>
7170
Type Validation </type-validation>
7271
Missing Index Warning </index-warning>
72+
Run Java Queries </run-java-queries>
7373
Release Notes <https://github.com/mongodb-js/intellij/blob/main/CHANGELOG.md>
7474
Submit Feedback </submit-feedback>

source/run-java-queries.txt

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
.. _intellij-run-java-queries:
2+
3+
================
4+
Run Java Queries
5+
================
6+
7+
.. default-domain:: mongodb
8+
9+
.. contents:: On this page
10+
:local:
11+
:backlinks: none
12+
:depth: 1
13+
:class: singlecol
14+
15+
Definition
16+
----------
17+
18+
The {+intellij-full+} enables you to run queries written in Java directly
19+
in the Database Explorer Playgrounds.
20+
21+
The Run button appears next to your MongoDB queries.
22+
23+
.. image:: /images/run-queries/intellij-run-icon.png
24+
:alt: Click the Run button to convert your Java query to mongosh syntax.
25+
26+
Behavior
27+
--------
28+
29+
When you click the Run button, the plugin automatically converts your
30+
Java query to ``mongosh`` syntax and opens a Playground file with the
31+
populated query.
32+
33+
For field values that are variables determined at runtime, the plugin
34+
creates a placeholder variable. You can populate this placeholder with
35+
a test value and run the query in the Playground.
36+
37+
Example
38+
-------
39+
40+
In this example, the Java query on the ``production.trips`` collection
41+
resemles the following:
42+
43+
.. code:: java
44+
:copyable: false
45+
46+
public List<Document> findCompletedTripsByDriver(String driverId) {
47+
return trips.find(Filters.and(
48+
Filters.eq(fieldName: "trip_status", value: "completed"),
49+
Filters.eq(fieldName: "driver_id", driverId)
50+
)).into(new ArrayList<>());
51+
}
52+
53+
The code example below shows the converted query from the Java code
54+
above.
55+
56+
.. code:: javascript
57+
:copyable: true
58+
59+
var driver_id = "<driver ID>"
60+
61+
db.getSiblingsDB("production")
62+
.getCollection("trips")
63+
.find( {
64+
"$and" : [
65+
{ "trip_status" : "completed" },
66+
{ "driver_id" : driver_id }
67+
]
68+
)
69+
70+
In this example, ``driver_id`` is a variable that holds a value
71+
determined at runtime. In order to test that your query outputs the
72+
results you expect, you must specify a test value by replacing
73+
``<driver ID>`` with the driver ID. For example,
74+
``driver_id = "1a2b3c4d5e"``.
75+
76+
Once you are satisfied with the query, you can run it in the Playground
77+
and view the query results.
78+
79+
.. image:: /images/run-queries/intellij-pg-icon-converted-query.png
80+
:alt: Click the Run button to run your query and view the results.

source/type-validation.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,3 +64,4 @@ Learn More
6464
- :ref:`intellij-connect`
6565
- :ref:`intellij-autocomplete`
6666
- :ref:`intellij-index-warning`
67+
- :ref:`intellij-run-java-queries`

0 commit comments

Comments
 (0)