Skip to content

Logic

Logic expressions combine boolean subexpressions with and, or, not, and exclusive (needs server 5.6.0+). The result is boolean and is used in the same places as comparison expressions: record filters, query and batch FilterExpression, XDR filters, and other APIs that accept filter expressions.

and / or / not follow trilean rules when inputs can be unknown (for example during the metadata-only phase of evaluation). exclusive tests whether exactly one of its boolean arguments is true. For how true, false, and unknown interact, see the execution model on the expressions overview.

Path expressions

and and or appear frequently inside path expression filter contexts such as allChildrenWithFilter and andFilter. See combining multiple filters in the path advanced guide.

The bookstore example on the path overview shows Exp.and with nested eq and lt on loop variables—typical of real document-style filters.

Ops

and

and(arg0, arg1, ...)
Description

Returns false if any ‘boolean_expr’ is false; otherwise, it returns true.

Arguments
NameType
arg0 boolean_expr
arg1 boolean_expr
... boolean_expr
Returns
boolean_value
Introduced
5.2.0.4
Example

Find records that have a stored user key and that key is an integer less than 1000 (metadata + key comparison). For the same combinator on nested bins inside path filters, see the bookstore example.

Expression exp = Exp.build(
Exp.and(
Exp.keyExists(),
Exp.lt(Exp.key(Exp.Type.INT), Exp.val(1000))));

exclusive

exclusive(arg0, arg1, ...)
Description

Returns true if exactly one ‘boolean_expr’ is true; otherwise, it returns false. This expression is helpful for testing whether multiple expressions are mutually exclusive.

Arguments
NameType
arg0 boolean_expr
arg1 boolean_expr
... boolean_expr
Returns
boolean_value
Introduced
5.6.0
Example

Find records where exactly one of these is true: string bin hand is hook, leg is peg, or pet is parrot. (Illustrates mutual-exclusion checks on independent bins—not nested path logic.)

Expression exp = Exp.build(
Exp.exclusive(
Exp.eq(Exp.stringBin("hand"), Exp.val("hook")),
Exp.eq(Exp.stringBin("leg"), Exp.val("peg")),
Exp.eq(Exp.stringBin("pet"), Exp.val("parrot"))));

not

not(arg)
Description

Returns true if the ‘boolean_expr’ is false; otherwise, it returns false.

Arguments
NameType
arg boolean_expr
Returns
boolean_value
Introduced
5.2.0.4
Example

Find records that do not have the primary key stored in record metadata (keyExists is false).

Expression exp = Exp.build(Exp.not(Exp.keyExists()));

or

or(arg0, arg1, ...)
Description

Returns true if any ‘boolean_expr’ is true; otherwise, it returns false.

Arguments
NameType
arg0 boolean_expr
arg1 boolean_expr
... boolean_expr
Returns
boolean_value
Introduced
5.2.0.4
Example

Find records where string bin country is either US or CA (same “one of several string values” idea as the expression index tutorial, which uses Or / Eq for target countries in Python).

Expression exp = Exp.build(
Exp.or(
Exp.eq(Exp.stringBin("country"), Exp.val("US")),
Exp.eq(Exp.stringBin("country"), Exp.val("CA"))));
Feedback

Was this page helpful?

What type of feedback are you giving?

What would you like us to know?

+Capture screenshot

Can we reach out to you?