Skip to content

DOCS-433 operator and does a short-circuit eval of expression #223

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 13, 2012
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 8 additions & 4 deletions source/reference/operator/and.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,14 @@ $and

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

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

Consider the following example:

Expand All @@ -27,7 +31,7 @@ $and
- ``price`` field value equals ``1.99`` **and**
- ``qty`` field value is less than ``20`` **and**
- ``sale`` field value is equal to ``true``.

MongoDB provides an implicit ``AND`` operation when specifying a
comma separated list of expressions. For example, you may write the
above query as:
Expand Down