Skip to content

Commit 179fbbf

Browse files
authored
DOCSP-44964-autocomplete (#9)
* DOCSP-44964-autocomplete * * * collection autocomplete * wording * db reference example * remove def * * * KD feedback * KMR feedback
1 parent 8bfce2a commit 179fbbf

File tree

6 files changed

+197
-1
lines changed

6 files changed

+197
-1
lines changed

source/autocomplete.txt

Lines changed: 79 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,88 @@ Autocomplete
66

77
.. default-domain:: mongodb
88

9+
.. meta::
10+
:description: Use the MongoDB for IntelliJ Plugin to autocomplete database, collection, and document field names.
11+
912
.. contents:: On this page
1013
:local:
1114
:backlinks: none
1215
:depth: 1
1316
:class: singlecol
1417

15-
Content on this page will be addressed in DOCSP-44964.
18+
The {+intellij-full+} provides autocomplete suggestions for database,
19+
collection, or field names based on the connected data source. For example,
20+
when you type a field name in a query, the plugin analyzes the MongoDB
21+
collection and document schema to automatically suggest valid field names.
22+
23+
To use the autocomplete feature, start typing in a document field, collection,
24+
or database name. Then press :kbd:`Ctrl` + :kbd:`Space` to display a drop-down
25+
list that shows the available suggestions.
26+
27+
Database Name Autocompletion
28+
----------------------------
29+
30+
To autocomplete database names, press :kbd:`Ctrl` + :kbd:`Space`
31+
inside the `getDatabase() <https://mongodb.github.io/mongo-java-driver/5.2/apidocs/mongodb-driver-sync/com/mongodb/client/MongoClient.html#getDatabase(java.lang.String)>`__
32+
method of a ``MongoClient`` instance.
33+
34+
The {+intellij-short+} displays a drop-down list of available database names,
35+
denoted by the ``MongoDB Database`` text and the database icon, as shown in
36+
the image below:
37+
38+
.. image:: /images/database-autocomplete.png
39+
:alt: Autocomplete database names in the IntelliJ Plugin.
40+
41+
Collection Name Autocompletion
42+
------------------------------
43+
44+
To autocomplete collection names, press :kbd:`Ctrl` + :kbd:`Space`
45+
inside the `getCollection() <https://mongodb.github.io/mongo-java-driver/5.2/apidocs/mongodb-driver-sync/com/mongodb/client/MongoDatabase.html#getCollection(java.lang.String)>`__
46+
method of a ``MongoClient`` instance.
47+
48+
The {+intellij-short+} displays a drop-down list of available collection names,
49+
denoted by the ``MongoDB Collection`` text and the collection icon, as shown in
50+
the image below:
51+
52+
.. image:: /images/collection-autocomplete.png
53+
:alt: Autocomplete collections names in the IntelliJ Plugin.
54+
55+
.. important::
56+
57+
Collection name autocompletion currently requires a complete query to
58+
suggest collection names. For example, you must write a query that specifies
59+
the database name and a document field for the {+intellij-short+} to suggest
60+
valid collection names.
61+
62+
Document Field Name Autocompletion
63+
----------------------------------
64+
65+
To autocomplete document field names, press :kbd:`Ctrl` + :kbd:`Space`
66+
inside one of the following `MongoCollection <https://mongodb.github.io/mongo-java-driver/5.1/apidocs/mongodb-driver-sync/com/mongodb/client/MongoCollection.html>`__
67+
methods:
68+
69+
- ``countDocuments``
70+
- ``deleteMany``
71+
- ``deleteOne``
72+
- ``distinct``
73+
- ``find``
74+
- ``findOneAndDelete``
75+
- ``findOneAndReplace``
76+
- ``findOneAndUpdate``
77+
- ``replaceOne``
78+
- ``updateMany``
79+
- ``updateOne``
80+
81+
The {+intellij-short+} displays a drop-down list of available field names,
82+
denoted by their data type and the document icon. For example, the image
83+
below shows autocomplete suggestions for fields that start with ``rat`` in the
84+
``sample_mflix.movies`` collection:
85+
86+
.. image:: /images/document-autocomplete.png
87+
:alt: Autocomplete document field names in the IntelliJ Plugin.
88+
89+
Learn More
90+
----------
91+
92+
- :ref:`intellij-connect`
93+
- :ref:`intellij-db-reference-validation`

source/db-reference-validation.txt

Lines changed: 115 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
1+
.. _intellij-db-reference-validation:
2+
3+
=============================
4+
Database Reference Validation
5+
=============================
6+
7+
.. default-domain:: mongodb
8+
9+
.. meta::
10+
:description: Use the MongoDB for IntelliJ Plugin to verify that specified databases, collections, and document fields exist in your data source.
11+
12+
.. contents:: On this page
13+
:local:
14+
:backlinks: none
15+
:depth: 1
16+
:class: singlecol
17+
18+
The {+intellij-full+} validates database references in your Java driver or
19+
Spring Criteria code to ensure that the specified database, collection, or field
20+
exists in the server.
21+
22+
If you reference a field, collection, or database name that isn't in
23+
your data source, the plugin shows a warning that indicates the reference
24+
doesn't exist.
25+
26+
To resolve the warning:
27+
28+
- Ensure that you're connected to the correct data source in the Connections
29+
Toolbar.
30+
31+
- Check that you're referencing the correct database and collection in your
32+
code.
33+
34+
- Verify that your database or collection contains the field you are trying to
35+
reference.
36+
37+
Non-existent Field Name
38+
------------------------
39+
40+
If you reference a field name that doesn't exist in the collection, the
41+
{+intellij-short+} raises the following warning:
42+
43+
.. code-block:: none
44+
:copyable: false
45+
46+
Field <fieldName> does not exist in collection <collectionName>.
47+
48+
Non-existent Collection Name
49+
----------------------------
50+
51+
If you reference a collection name that doesn't exist in the database, the
52+
{+intellij-short+} raises the following warning:
53+
54+
.. code-block:: none
55+
:copyable: false
56+
57+
Cannot resolve <collectionName> collection in <dbName> database in the
58+
connected data source.
59+
60+
Non-existent Database Name
61+
--------------------------
62+
63+
If you reference a database that doesn't exist in the data source, the
64+
{+intellij-short+} raises the following warning:
65+
66+
.. code-block:: none
67+
:copyable: false
68+
69+
Cannot resolve <dbName> database reference in the connected data source.
70+
71+
Example
72+
-------
73+
74+
The following example references the ``sample_mflix`` database, which contains
75+
data on movies and movie theaters, from the :ref:`Atlas sample datasets
76+
<sample-mflix>`.
77+
78+
The sample code attempts to call a ``restaurant_name`` collection:
79+
80+
.. code-block:: java
81+
:copyable: false
82+
:emphasize-lines: 3
83+
84+
public List<Document> getHundredYearOldMovies() {
85+
return client.getDatabase("sample_mflix")
86+
.getCollection("restaurant_name")
87+
.find(Filters.eq("year", 1924))
88+
.into(new ArrayList<>());
89+
}
90+
91+
Because the collection doesn't exist in the ``sample_mflix`` database, the
92+
{+intellij-short+} raises a warning that the collection cannot be resolved:
93+
94+
``Cannot resolve "restaurant_name" collection in "sample_mflix" database in the
95+
connected data source.``
96+
97+
To resolve the warning, reference a collection that exists in the
98+
``sample_mflix`` database:
99+
100+
.. code-block:: java
101+
:copyable: false
102+
:emphasize-lines: 3
103+
104+
public List<Document> getHundredYearOldMovies() {
105+
return client.getDatabase("sample_mflix")
106+
.getCollection("movies")
107+
.find(Filters.eq("year", 1924))
108+
.into(new ArrayList<>());
109+
}
110+
111+
Learn More
112+
----------
113+
114+
- :ref:`intellij-connect`
115+
- :ref:`intellij-autocomplete`
121 KB
Loading
351 KB
Loading
180 KB
Loading

source/index.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@ The {+intellij-short+} currently supports the following features:
3838
- :ref:`Autocomplete <intellij-autocomplete>` for database, collection, and
3939
document field names.
4040

41+
- :ref:`Database reference validation <intellij-db-reference-validation>`.
42+
4143
- :ref:`Type validation <intellij-type-validation>` of document fields.
4244

4345
- :ref:`Missing index warnings <intellij-index-warning>` for Java queries.
@@ -65,6 +67,7 @@ To learn more about submitting feedback, see :ref:`intellij-submit-feedback`.
6567
Install </install>
6668
Connect </connect>
6769
Autocomplete </autocomplete>
70+
Database Reference Validation </db-reference-validation>
6871
Type Validation </type-validation>
6972
Missing Index Warning </index-warning>
7073
Release Notes <https://github.com/mongodb-js/intellij/blob/main/CHANGELOG.md>

0 commit comments

Comments
 (0)