File tree Expand file tree Collapse file tree 1 file changed +7
-9
lines changed
source/reference/operator/query Expand file tree Collapse file tree 1 file changed +7
-9
lines changed Original file line number Diff line number Diff line change 25
25
.. note::
26
26
27
27
MongoDB provides an implicit ``AND`` operation when specifying a
28
- comma separated list of expressions. Using an explicit ``AND``
29
- with the :query:`$and` operator is necessary when the same field
30
- or operator has to be specified in multiple expressions.
28
+ comma separated list of expressions.
31
29
32
30
Examples
33
31
--------
@@ -63,17 +61,17 @@ Consider the following example:
63
61
.. code-block:: javascript
64
62
65
63
db.inventory.find( {
66
- $and : [
67
- { $or : [ { price : 0.99 } , { price : 1.99 } ] },
68
- { $or : [ { sale : true }, { qty : { $lt : 20 } } ] }
64
+ $and: [
65
+ { $or: [ { qty: { $lt : 10 } } , { qty : { $gt: 50 } } ] },
66
+ { $or: [ { sale: true }, { price : { $lt : 5 } } ] }
69
67
]
70
68
} )
71
69
72
70
This query will select all documents where:
73
71
74
- - the ``price `` field value equals ``0.99 `` or ``1.99 ``, **and**
75
- - the ``sale`` field value is equal to ``true`` **or** the ``qty ``
76
- field value is less than ``20 ``.
72
+ - the ``qty `` field value is less than ``20 `` or greater than ``50 ``, **and**
73
+ - the ``sale`` field value is equal to ``true`` **or** the ``price ``
74
+ field value is less than ``5 ``.
77
75
78
76
This query cannot be constructed using an implicit ``AND`` operation,
79
77
because it uses the :query:`$or` operator more than once.
You can’t perform that action at this time.
0 commit comments