If
If( cond_expr, true_expr, false_expr )
If( cond_expr, true_expr, false_expr )
If( cond_expr, true_expr, false_expr )
If( cond_expr, true_expr, false_expr )
if_( cond_expr, true_expr, false_expr )
If( cond_expr, true_expr, false_expr )
Description
The If
function evaluates and returns the true_expr
or
false_expr
expression, depending on the value of the cond
expression. If the cond
expression evaluates to anything other than a
Boolean, If
returns an "invalid argument" error.
Any valid Fauna Query Language expression is acceptable, including null
.
The If function requires three parameters, and using them
is equivalent to if-then-else. This means that you cannot use
If to express if-then logic. Instead, you might find the
Filter function useful, as it could be used to remove
documents from consideration, in bulk, that might otherwise require
If logic.
|
Parameters
Parameter | Type | Definition and Requirements |
---|---|---|
|
Boolean Expression |
The conditional expression to be evaluated and tested for |
|
Expression |
The expression or variable to return if |
|
Expression |
The expression or variable to return if |
Returns
The evaluation of either the true_expr
or false_expr
expression,
depending on the evaluation of the cond
expression.
Examples
The following query evaluates the cond
expression, which is the
condition that needs to be tested, and then determines that cond
returns true
. This causes the second argument, the true_expr
expression, to be evaluated and returned. The third argument, the
false_expr
expression, is never evaluated.
StringV(was true)
was true
"was true"
was true
was true
'was true'
Is this article helpful?
Tell Fauna how the article can be improved:
Visit Fauna's forums
or email docs@fauna.com
Thank you for your feedback!