@@ -13,7 +13,7 @@ Specify a Query
1313Overview
1414--------
1515
16- In this guide, you can learn how to specify a query in the MongoDB Java
16+ In this guide, you can learn how to specify a query in the MongoDB Kotlin
1717driver.
1818
1919Most CRUD operations allow you to narrow the set of matched documents by
@@ -44,6 +44,11 @@ The examples in this guide use the following documents in the
4444 { "_id": 7, "color": "green", "qty": 8, "vendor": ["C", "E"], "rating": 7 }
4545 { "_id": 8, "color": "black", "qty": 7, "vendor": ["A", "C", "D"] }
4646
47+ This data is modeled with the following Kotlin data class:
48+
49+ .. literalinclude:: /examples/generated/QueryDocumentTest.snippet.query-data-model.kt
50+ :language: kotlin
51+
4752.. _query-comparison:
4853
4954Comparison Operators
@@ -58,20 +63,17 @@ The following example uses the ``Filters.gt()`` method to match all
5863documents where the value of ``qty`` is greater than ``7`` in the
5964``paint_purchases`` collection:
6065
61- .. literalinclude:: /includes/fundamentals/code-snippets/Query.java
62- :language: java
63- :dedent:
64- :start-after: begin comparisonFilter
65- :end-before: end comparisonFilter
66+ .. io-code-block::
6667
67- The following shows the output of the preceding query:
68+ .. input:: /examples/generated/QueryDocumentTest.snippet.comparison-filter.kt
69+ :language: kotlin
6870
69- .. code-block :: json
70- :copyable: false
71+ .. output ::
72+ :language: console
7173
72- { "_id": 1, "color": "red", " qty": 9, "vendor": ["A", "E"] }
73- { "_id": 2, "color": "purple", " qty": 8, "vendor": ["B", "D", "F" ], " rating": 5 }
74- { "_id": 7, "color": "green", " qty": 8, "vendor": ["C", "E" ], " rating": 7 }
74+ PaintOrder(id= 1, qty= 9, color=red, vendor=[A, E], rating=null)
75+ PaintOrder(id= 2, qty= 8, color=purple, vendor=[B, D, F ], rating=5)
76+ PaintOrder(id= 7, qty= 8, color=green, vendor=[C, E ], rating=7)
7577
7678.. _query-logical:
7779
@@ -88,19 +90,16 @@ documents where the value of ``qty`` is less than or equal to ``5`` and
8890the value of ``color`` is not ``"pink"`` in the ``paint_purchases``
8991collection:
9092
91- .. literalinclude:: /includes/fundamentals/code-snippets/Query.java
92- :language: java
93- :dedent:
94- :start-after: begin logicalFilter
95- :end-before: end logicalFilter
93+ .. io-code-block::
9694
97- The following shows the output of the preceding query:
95+ .. input:: /examples/generated/QueryDocumentTest.snippet.logical-filter.kt
96+ :language: kotlin
9897
99- .. code-block :: json
100- :copyable: false
98+ .. output ::
99+ :language: console
101100
102- { "_id": 3, "color": "blue", " qty": 5, "vendor": ["A", "E"] }
103- { "_id": 5, "color": "yellow", " qty": 4, "vendor": ["A", "B"] }
101+ PaintOrder(id= 3, qty= 5, color=blue, vendor=[A, E], rating=null)
102+ PaintOrder(id= 5, qty= 4, color=yellow, vendor=[A, B], rating=null)
104103
105104.. _query-arrays:
106105
@@ -114,19 +113,16 @@ The following example uses the ``Filters.size()`` method to match
114113documents where the size of the ``vendor`` list is ``3`` in the
115114``paint_purchases`` collection:
116115
117- .. literalinclude:: /includes/fundamentals/code-snippets/Query.java
118- :language: java
119- :dedent:
120- :start-after: begin arrayFilter
121- :end-before: end arrayFilter
116+ .. io-code-block::
122117
123- The following shows the output of the preceding query:
118+ .. input:: /examples/generated/QueryDocumentTest.snippet.array-filter.kt
119+ :language: kotlin
124120
125- .. code-block :: json
126- :copyable: false
121+ .. output ::
122+ :language: console
127123
128- { "_id": 2, "color": "purple", " qty": 8, "vendor": ["B", "D", "F" ], " rating": 5 }
129- { "_id": 8, "color": "black", " qty": 7, "vendor": ["A", "C", "D"] }
124+ PaintOrder(id= 2, qty= 8, color=purple, vendor=[B, D, F ], rating=5)
125+ PaintOrder(id= 8, qty= 7, color=black, vendor=[A, C, D], rating=null)
130126
131127.. _query-elements:
132128
@@ -138,20 +134,17 @@ Element operators query data based on the presence or type of a field.
138134The following example uses the ``Filters.exists()`` method to match
139135documents that have a ``rating`` in the ``paint_purchases`` collection:
140136
141- .. literalinclude:: /includes/fundamentals/code-snippets/Query.java
142- :language: java
143- :dedent:
144- :start-after: begin elementFilter
145- :end-before: end elementFilter
137+ .. io-code-block::
146138
147- The following shows the output of the preceding query:
139+ .. input:: /examples/generated/QueryDocumentTest.snippet.element-filter.kt
140+ :language: kotlin
148141
149- .. code-block :: json
150- :copyable: false
142+ .. output ::
143+ :language: console
151144
152- { "_id": 2, "color": "purple", " qty": 8, "vendor": ["B", "D", "F" ], " rating": 5 }
153- { "_id": 4, "color": "white", " qty": 6, "vendor": ["D" ], " rating": 9 }
154- { "_id": 7, "color": "green", " qty": 8, "vendor": ["C", "E" ], " rating": 7 }
145+ PaintOrder(id= 2, qty= 8, color=purple, vendor=[B, D, F ], rating=5)
146+ PaintOrder(id= 4, qty= 6, color=white, vendor=[D ], rating=9)
147+ PaintOrder(id= 7, qty= 8, color=green, vendor=[C, E ], rating=7)
155148
156149.. _query-evaluation:
157150
@@ -165,19 +158,16 @@ The following example uses the ``Filters.regex()`` method to match
165158documents that have a ``color`` ending with the letter ``"k"`` in the
166159``paint_purchases`` collection:
167160
168- .. literalinclude:: /includes/fundamentals/code-snippets/Query.java
169- :language: java
170- :dedent:
171- :start-after: begin evaluationFilter
172- :end-before: end evaluationFilter
161+ .. io-code-block::
173162
174- The following shows the output of the preceding query:
163+ .. input:: /examples/generated/QueryDocumentTest.snippet.evaluation-filter.kt
164+ :language: kotlin
175165
176- .. code-block :: json
177- :copyable: false
166+ .. output ::
167+ :language: console
178168
179- { "_id": 6, "color": "pink", " qty": 3, "vendor": ["C"] }
180- { "_id": 8, "color": "black", " qty": 7, "vendor": ["A", "C", "D"] }
169+ PaintOrder(id= 6, qty= 3, color=pink, vendor=[C], rating=null)
170+ PaintOrder(id= 8, qty= 7, color=black, vendor=[A, C, D], rating=null)
181171
182172For more information about the operators mentioned in this guide,
183173see the following Server Manual Entries:
0 commit comments