Skip to content

Commit 6250a0b

Browse files
committed
update $and
1 parent 932b8ba commit 6250a0b

File tree

1 file changed

+7
-9
lines changed
  • source/reference/operator/query

1 file changed

+7
-9
lines changed

source/reference/operator/query/and.txt

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,7 @@ $and
2525
.. note::
2626

2727
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.
3129

3230
Examples
3331
--------
@@ -63,17 +61,17 @@ Consider the following example:
6361
.. code-block:: javascript
6462

6563
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 } } ] }
6967
]
7068
} )
7169

7270
This query will select all documents where:
7371

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``.
7775

7876
This query cannot be constructed using an implicit ``AND`` operation,
7977
because it uses the :query:`$or` operator more than once.

0 commit comments

Comments
 (0)