Skip to content

Commit 964045d

Browse files
committed
DOCS-433 operator does a short-circuit eval of expression
1 parent 4b4a1bc commit 964045d

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

source/reference/operator/and.txt

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,14 @@ $and
1010

1111
*Syntax*: ``{ $and: [ { <expression1> }, { <expression2> } , ... , { <expressionN> } ] }``
1212

13-
:operator:`$and` performs a logical ``AND`` operation on an array
14-
of *two or more* expressions (e.g. ``<expression1>``,
13+
:operator:`$and` performs a logical ``AND`` operation on an array of
14+
*two or more* expressions (e.g. ``<expression1>``,
1515
``<expression2>``, etc.) and selects the documents that satisfy
16-
*all* the expressions in the array.
16+
*all* the expressions in the array. With the :operator:`$and`
17+
operator, MongoDB performs a short-circuit evaluation of the
18+
expressions. If the first expression ``<expression1>`` evaluates to
19+
``false``, MongoDB will skip the evaluation of the remaining
20+
expressions.
1721

1822
Consider the following example:
1923

@@ -27,7 +31,7 @@ $and
2731
- ``price`` field value equals ``1.99`` **and**
2832
- ``qty`` field value is less than ``20`` **and**
2933
- ``sale`` field value is equal to ``true``.
30-
34+
3135
MongoDB provides an implicit ``AND`` operation when specifying a
3236
comma separated list of expressions. For example, you may write the
3337
above query as:

0 commit comments

Comments
 (0)