Methods
conditional(thenExpr, elseExpr)
Creates a conditional expression that evaluates to the 'then' expression
if this expression evaluates to true,
or evaluates to the 'else' expression if this expressions evaluates false.
// If 'age' is greater than 18, return "Adult"; otherwise, return "Minor".
field("age").greaterThanOrEqual(18).conditional(constant("Adult"), constant("Minor"));
Parameters:
| Name | Type | Description |
|---|---|---|
thenExpr |
The expression to evaluate if the condition is true. |
|
elseExpr |
The expression to evaluate if the condition is false. |
Returns:
| Type | Description |
|---|---|
|
A new |
countIf()
Creates an aggregation that finds the count of input documents satisfying this boolean expression.
// Find the count of documents with a score greater than 90
field("score").greaterThan(90).countIf().as("highestScore");
Returns:
| Type | Description |
|---|---|
|
A new |
not()
Creates an expression that negates this boolean expression.
// Find documents where the 'tags' field does not contain 'completed'
field("tags").arrayContains("completed").not();
Returns:
| Type | Description |
|---|---|
|
A new |