@@ -21,29 +21,31 @@ of documents.
21
21
To match a subset of documents, specify a **query filter** containing
22
22
your **match criteria**. Match criteria consist of the fields and
23
23
values you want documents to match. A query filter contains at least
24
- one set of match criteria to determine which documents to return. An
25
- empty query filter matches all of the documents in a collection.
24
+ one set of match criteria to determine which documents to return. If you
25
+ use an empty query filter in a find operation, the driver matches all
26
+ the documents in the collection.
26
27
27
28
In a query filter, you can match fields with :ref:`literal values
28
29
<rust-literal-values>` or with query operators. Query operators allow
29
30
you to perform mathematical or logical operations to locate documents within a collection.
30
31
31
- To match criteria with literal values use the following format:
32
+ To match documents by using literal values, use the following format:
32
33
33
34
.. code-block:: rust
34
35
:copyable: false
35
36
36
37
let filter = doc! { "<field>": "<value>" };
37
38
38
- To match criteria that include query operators use the following format:
39
+ To create match criteria that include query operators, use the following
40
+ format:
39
41
40
42
.. code-block:: rust
41
43
:copyable: false
42
44
43
45
let filter = doc! { "<field>": doc! { "<operator>": "<value>" } };
44
46
45
- The examples in the following sections show how to specify queries by using the ``find()``
46
- method to match documents in a collection.
47
+ The examples in the following sections show how to specify queries by
48
+ using the ``find()`` method to match documents in a collection.
47
49
48
50
This guide includes the following sections:
49
51
@@ -71,7 +73,7 @@ This guide includes the following sections:
71
73
query based on the equivalent bits set of a base-10 value
72
74
73
75
- :ref:`Array <rust-array-operators>`: describes how to query
74
- a collection based on data within an array-valued field.
76
+ a collection based on data within an array-valued field
75
77
76
78
.. _rust-query-sample-data:
77
79
@@ -115,20 +117,14 @@ that has the value of ``pear``:
115
117
:language: json
116
118
:visible: false
117
119
118
- {
119
- "_id": 4,
120
- "name": "pear",
121
- "quantity": 28,
122
- "vendors": [
123
- "A",
124
- "C"
125
- ]
126
- }
120
+ Document({"_id": Int32(4), "name": String("pear"), "quantity":
121
+ Int32(28), "vendors": Array([String("A"), String("C")])})
127
122
128
123
.. note::
129
124
130
- Literal value queries function identically to queries that use the ``$eq`` comparison
131
- operator. For example, the following queries are equivalent:
125
+ Literal value queries function identically to queries that use the
126
+ ``$eq`` comparison operator. For example, the following queries are
127
+ equivalent:
132
128
133
129
.. code-block:: rust
134
130
@@ -171,25 +167,12 @@ documents with a ``quantity`` value greater than ``5``:
171
167
:language: json
172
168
:visible: false
173
169
174
- {
175
- "_id": 1,
176
- "name": "orange",
177
- "quantity": 7
178
- }
179
- {
180
- "_id": 3,
181
- "name": "banana",
182
- "quantity": 36
183
- }
184
- {
185
- "_id": 4,
186
- "name": "pear",
187
- "quantity": 28,
188
- "vendors": [
189
- "A",
190
- "C"
191
- ]
192
- }
170
+ Document({"_id": Int32(1), "name": String("orange"), "quantity":
171
+ Int32(7)})
172
+ Document({"_id": Int32(3), "name": String("banana"), "quantity":
173
+ Int32(36)})
174
+ Document({"_id": Int32(4), "name": String("pear"), "quantity":
175
+ Int32(28), "vendors": Array([String("A"), String("C")])})
193
176
194
177
For more information on comparison operators, see :manual:`Comparison
195
178
Query Operators </reference/operator/query-comparison/>` in the Server manual.
@@ -224,11 +207,8 @@ divisible by ``3``:
224
207
:language: json
225
208
:visible: false
226
209
227
- {
228
- "_id": 3,
229
- "name": "banana",
230
- "quantity": 36
231
- }
210
+ Document({"_id": Int32(3), "name": String("banana"), "quantity":
211
+ Int32(36)})
232
212
233
213
.. note::
234
214
@@ -247,7 +227,7 @@ divisible by ``3``:
247
227
.. code-block:: rust
248
228
249
229
my_coll.find(doc! {
250
- $and: vec! [
230
+ $and: [
251
231
doc! { "price": { "$eq": 5 }},
252
232
doc! { "quantity": { "$gt": 4 }}
253
233
]
@@ -284,12 +264,8 @@ field:
284
264
:language: json
285
265
:visible: false
286
266
287
- {
288
- "_id": 2,
289
- "name": "apple",
290
- "quantity": 4,
291
- "description": "Granny Smith"
292
- }
267
+ Document({"_id": Int32(2), "name": String("apple"), "quantity":
268
+ Int32(4), "description": String("Granny Smith")})
293
269
294
270
For a full list of element operators, see :manual:`Element
295
271
Query Operators </reference/operator/query-element/>` in the Server manual.
@@ -324,11 +300,8 @@ for documents with a ``quantity`` value that is divisible by 3:
324
300
:language: json
325
301
:visible: false
326
302
327
- {
328
- "_id": 3,
329
- "name": "banana",
330
- "quantity": 36
331
- }
303
+ Document({"_id": Int32(3), "name": String("banana"), "quantity":
304
+ Int32(36)})
332
305
333
306
For a full list of evaluation operators, see :manual:`Evaluation
334
307
Query Operators </reference/operator/query-evaluation/>` in the Server manual.
@@ -362,11 +335,8 @@ bits set as ``7``, which is equivalent to ``00000111`` in binary:
362
335
:language: json
363
336
:visible: false
364
337
365
- {
366
- "_id": 1,
367
- "name": "orange",
368
- "quantity": 7
369
- }
338
+ Document({"_id": Int32(1), "name": String("orange"), "quantity":
339
+ Int32(7)})
370
340
371
341
For a full list of bitwise operators, see :manual:`Bitwise
372
342
Query Operators </reference/operator/query-bitwise/>` in the Server manual.
@@ -399,22 +369,18 @@ The following example matches documents where the ``vendor`` contains
399
369
:language: json
400
370
:visible: false
401
371
402
- {
403
- "_id": 4,
404
- "name": "pear",
405
- "quantity": 28,
406
- "vendors": [
407
- "A",
408
- "C"
409
- ]
410
- }
372
+ Document({"_id": Int32(4), "name": String("pear"), "quantity":
373
+ Int32(28), "vendors": Array([String("A"), String("C")])})
411
374
412
375
For a full list of bitwise operators, see :manual:`Array
413
376
Query Operators </reference/operator/query-array/>` in the Server manual.
414
377
415
378
Additional Information
416
379
----------------------
417
380
381
+ To learn more about find operations, see the :ref:`rust-retrieve-guide`
382
+ guide.
383
+
418
384
To learn more about query operators, see :manual:`Query Selectors
419
385
</reference/operator/query/>` in the Server manual.
420
386
0 commit comments