Skip to main content
Version: Next

Logical Operators

The logical operators are used to combine multiple conditions in a query.

The following logical operators are supported:

OperatorDescription
$and | $all_ofLogical AND operator. For result to be true, all conditions must be true.
$or | $any_ofLogical OR operator. For result to be true, at least one condition must be true.
$xor | $one_ofLogical XOR operator. For result to be true, exactly one condition must be true.
$not | $none_ofLogical NOT operator. For result to be true, all conditions must be false.
$inChecks if the first expression is equal to any of the following expressions.
$ninChecks if the first expression is not equal to any of the following expressions.

$and | $all_of

The $and or $all_of operator is used to combine multiple conditions in a query. The result is true only if all conditions are true.

Syntax

{
"$and" | "$all_of: [
{ <expression_1> },
{ <expression_2> },
...
]
}

Behavior

The operator evaluates each condition in the array and returns true only if all conditions are true. It stops evaluating conditions as soon as one of them is false. Empty list of conditions is always true.

Examples

Object notation:

{
"&label_name_1": { "$and": "&label_name_2" }
}

Array notation:

{
"$all_of": [
{ "&label_name": { "$gt": 10 } },
{ "&label_name": { "$lt": 20 } }
]
}

$or | $any_of

The $or or $any_of operator is used to combine multiple conditions in a query. The result is true if at least one condition is true.

Syntax

{
"$or" | "$any_of": [
{ <expression_1> },
{ <expression_2>},
...
]
}

Behavior

The operator evaluates each condition in the array and returns true if at least one condition is true. It stops evaluating conditions as soon as one of them is true. Empty list of conditions is always false.

Examples

Object notation:

{
"&label_name_1": { "$or": "&label_name_2" }
}

Array notation:

{
"$any_of": [
{ "&label_name": { "$gt": 10 } },
{ "&label_name": { "$lt": 20 } }
]
}

$xor | $one_of

The $xor or $one_of operator is used to combine multiple conditions in a query. The result is true only if exactly one condition is true.

Syntax

{
"$xor" | "$one_of": [
{ <expression_1> },
{ <expression_2> },
...
]
}

Behavior

The operator evaluates each condition in the array and returns true only if exactly one condition is true. It stops evaluating conditions as soon as more than one of them is true. Empty list of conditions is always false.

Examples

Object notation:

{
"&label_name_1": { "$xor": "&label_name_2" }
}

Array notation:

{
"$one_of": [
{ "&label_name": { "$gt": 10 } },
{ "&label_name": { "$lt": 20 } }
]
}

$not | $none_of

The $not or $none_of operator is used to negate a condition in a query. The result is true only if all conditions are false.

Syntax

{
"$not" | "$none_of": [
{ <expression_1> },
{ <expression_2> },
]
}

Behavior

The operator evaluates each condition in the array and returns true only if all conditions are false. It stops evaluating conditions as soon as one of them is true. Empty list of conditions is always true.

Examples

Object notation:

{
"&label_name_1": { "$not": "&label_name_2" }
}

Array notation:

{
"$none_of": [
{ "&label_name": { "$gt": 10 } },
{ "&label_name": { "$lt": 20 } }
]
}

$in

The $in operator is used to check if the first expression is equal to any of the following expressions.

Syntax

{
"$in": [ <expression as label reference>, <expression as element 1>, <expression as element 2>, ... ]
}

Behavior

The operator evaluates the first expression and checks if it is equal to any of the following expressions. It evaluates all of the following expressions to determine if the first expression is not equal to any of them and stops evaluating as soon as one of the following expressions is equal to the first expression.

Examples

Array notation:

{
"$in": ["&severity", "high", "critical"]
}

$nin

The $nin operator is used to check if the first expression is not equal to any of the following expressions.

Syntax

{
"$nin": [ <expression as label reference>, <expression as element 1>, <expression as element 2>, ... ]
}

Behavior

The operator evaluates the first expression and checks if it is equal to any of the following expressions. It evaluates all of the following expressions to determine if the first expression is not equal to any of them and stops evaluating if any of the following expressions is equal to the first expression.

Examples

Array notation:

{
"$nin": ["&severity", "low", "medium"]
}