@@ -122,15 +122,19 @@ Examples
122
122
123
123
[
124
124
{
125
- "_id":{"$oid":"5a9427648b0beebeb69579cc"},
126
125
"name":"Andrea Le",
127
126
128
127
"version":5,
129
128
"scores":[85, 95, 75],
130
129
"dateCreated":{"$date":"2003-03-26"}
131
130
},
132
131
{
133
- "_id":{"$oid":"5a9427648b0beebeb69579cf"},
132
+
133
+ "version":4,
134
+ "scores":[90, 90, 70],
135
+ "dateCreated":{"$date":"2001-04-15"}
136
+ },
137
+ {
134
138
"name":"Greg Powell",
135
139
136
140
"version":1,
@@ -166,29 +170,74 @@ Examples
166
170
.. tab:: Filter for a Match
167
171
:tabid: match
168
172
169
- The following :ref:`query filter <query-bar-filter>` uses the
170
- :manual:`$eq operator </reference/operator/query/eq/>` to find
171
- all documents where ``name`` is "Andrea Le" .
173
+ The following :ref:`query filter <query-bar-filter>` finds
174
+ all documents where the value of ``name`` is "Andrea Le".
172
175
173
176
.. code-block:: shell
174
177
175
- { name: { $eq: "Andrea Le" } }
178
+ { name: "Andrea Le" }
176
179
177
180
The query returns the following document because the ``name``
178
- field value in the document is an exact match.
181
+ field value is an exact match.
179
182
180
183
.. code-block:: JSON
181
184
:copyable: false
182
185
183
186
{
184
- "_id":ObjectId("5a9427648b0beebeb69579cc") ,
187
+ "_id": {"$oid": "5e349915cebae490877d561d"} ,
185
188
"name":"Andrea Le",
186
189
187
190
"version":5,
188
191
"scores":[85, 95, 75],
189
- "dateCreated":2003-03-26T00:00:00.000+00:00
192
+ "dateCreated":{"$date":" 2003-03-26"}
190
193
}
191
194
195
+ .. tab:: Filter by Exclusion ($not)
196
+ :tabid: not
197
+
198
+ The following :ref:`query filter <query-bar-filter>` uses the
199
+ :manual:`$not operator </reference/operator/query/not/>` to find
200
+ all documents where:
201
+
202
+ - The value of the ``name`` field is **not** equal to "Andrea Le",
203
+ or
204
+
205
+ - The ``name`` field does not exist
206
+
207
+ .. code-block:: shell
208
+
209
+ { name: { $not: { $eq: "Andrea Le" } } }
210
+
211
+ The query returns the following documents because the ``name``
212
+ field either does not exist or its value is something other than
213
+ "Andrea Le".
214
+
215
+ .. code-block:: JSON
216
+ :copyable: false
217
+
218
+ [
219
+ {
220
+ "_id":{"$oid":"5e349915cebae490877d561e"},
221
+
222
+ "version":4,
223
+ "scores":[90, 90, 75],
224
+ "dateCreated":{"$date":"2001-04-15"}
225
+ },
226
+ {
227
+ "_id":{"$oid":"5a9427648b0beebeb69579cf"},
228
+ "name":"Greg Powell",
229
+
230
+ "version":1,
231
+ "scores":[65, 75, 80],
232
+ "dateCreated":{"$date":"1999-02-10"}
233
+ }
234
+ ]
235
+
236
+ .. seealso::
237
+
238
+ For a complete list of logical query operators, see
239
+ :manual:`Logical Query Operators</reference/operator/query-logical/>`.
240
+
192
241
.. tab:: Filter by Comparison
193
242
:tabid: compare
194
243
@@ -201,20 +250,34 @@ Examples
201
250
202
251
{ version: { $lte: 4 } }
203
252
204
- The query returns the following document because the value of
205
- the ``version`` field in the document is less than ``4``.
253
+ The query returns the following documents because
254
+ the ``version`` field values are less than or equal to ``4``.
206
255
207
256
.. code-block:: JSON
208
257
:copyable: false
209
258
210
- {
211
- "_id":ObjectId("5a9427648b0beebeb69579cf"),
212
- "name":"Greg Powell",
213
-
214
- "version":1,
215
- "scores":[65, 75, 80],
216
- "dateCreated":1999-02-10T00:00:00.000+00:00
217
- }
259
+ [
260
+ {
261
+ "_id":{"$oid":"5e349915cebae490877d561e"},
262
+
263
+ "version":4,
264
+ "scores":[90, 90, 75],
265
+ "dateCreated":{"$date":"2001-04-15"}
266
+ },
267
+ {
268
+ "_id":{"$oid":"5a9427648b0beebeb69579cf"},
269
+ "name":"Greg Powell",
270
+
271
+ "version":1,
272
+ "scores":[65, 75, 80],
273
+ "dateCreated":{"$date":"1999-02-10"}
274
+ }
275
+ ]
276
+
277
+ .. seealso::
278
+
279
+ For a complete list of comparison operators, see
280
+ :manual:`Comparison Query Operators </reference/operator/query-comparison/>`.
218
281
219
282
.. tab:: Filter by Date
220
283
:tabid: date
@@ -229,22 +292,32 @@ Examples
229
292
230
293
{ dateCreated: { $gt: Date('2000-06-22') } }
231
294
232
- The query returns the following document because the value of
233
- the ``dateCreated`` field is after June 22, 2000.
295
+ The query returns the following documents because
296
+ the ``dateCreated`` field values are after June 22, 2000.
234
297
235
298
.. code-block:: JSON
236
299
:copyable: false
237
300
238
- {
239
- "_id":ObjectId("5a9427648b0beebeb69579cc"),
240
- "name":"Andrea Le",
241
-
242
- "version":1,
243
- "scores":[85, 95, 75],
244
- "dateCreated":2003-03-26T00:00:00.000+00:00
245
- }
301
+ [
302
+ {
303
+ "_id": {"$oid": "5e349915cebae490877d561d"},
304
+ "name":"Andrea Le",
305
+
306
+ "version":5,
307
+ "scores":[85, 95, 75],
308
+ "dateCreated":{"$date":"2003-03-26"}
309
+ },
310
+ {
311
+ "_id":{"$oid":"5e349915cebae490877d561e"},
312
+
313
+ "version":4,
314
+ "scores":[90, 90, 75],
315
+ "dateCreated":{"$date":"2001-04-15"}
316
+ }
317
+ ]
318
+
246
319
247
- .. tab:: Filter by Elements in an Array
320
+ .. tab:: Filter by Array Elements
248
321
:tabid: array
249
322
250
323
The following :ref:`query filter <query-bar-filter>` uses the
@@ -263,12 +336,12 @@ Examples
263
336
:copyable: false
264
337
265
338
{
266
- "_id":ObjectId("5a9427648b0beebeb69579cc") ,
339
+ "_id": {"$oid": "5e349915cebae490877d561d"} ,
267
340
"name":"Andrea Le",
268
341
269
- "version":1 ,
342
+ "version":5 ,
270
343
"scores":[85, 95, 75],
271
- "dateCreated":2003-03-26T00:00:00.000+00:00
344
+ "dateCreated":{"$date":" 2003-03-26"}
272
345
}
273
346
274
347
For more query examples, see
0 commit comments