docs-devsite/firestore_pipelines.booleanexpression.md
Project: /docs/reference/js/_project.yaml Book: /docs/reference/_book.yaml page_type: reference
{% comment %} DO NOT EDIT THIS FILE! This is generated by the JS SDK team, and any local changes will be overwritten. Changes should be made in the source code at https://github.com/firebase/firebase-js-sdk {% endcomment %}
An interface that represents a filter condition.
<b>Signature:</b>
export declare abstract class BooleanExpression extends Expression
<b>Extends:</b> Expression
| Method | Modifiers | Description |
|---|---|---|
| conditional(thenExpr, elseExpr) | Creates a conditional expression that evaluates to the 'then' expression if <code>this</code> expression evaluates to <code>true</code>, or evaluates to the 'else' expression if <code>this</code> expressions evaluates <code>false</code>. | |
| countIf() | Creates an aggregation that finds the count of input documents satisfying this boolean expression. | |
| ifError(catchValue) | Creates an expression that returns the <code>catch</code> argument if there is an error, else return the result of this expression. | |
| ifError(catchValue) | Creates an expression that returns the <code>catch</code> argument if there is an error, else return the result of this expression. | |
| ifError(catchValue) | Creates an expression that returns the <code>catch</code> argument if there is an error, else return the result of this expression. | |
| ifError(catchValue) | Creates an expression that returns the <code>catch</code> argument if there is an error, else return the result of this expression. | |
| not() | Creates an expression that negates this boolean expression. |
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<!-- -->.
<b>Signature:</b>
conditional(thenExpr: Expression, elseExpr: Expression): FunctionExpression;
| Parameter | Type | Description |
|---|---|---|
| thenExpr | Expression | The expression to evaluate if the condition is true. |
| elseExpr | Expression | The expression to evaluate if the condition is false. |
<b>Returns:</b>
A new Expression representing the conditional expression.
// If 'age' is greater than 18, return "Adult"; otherwise, return "Minor".
field("age").greaterThanOrEqual(18).conditional(constant("Adult"), constant("Minor"));
Creates an aggregation that finds the count of input documents satisfying this boolean expression.
<b>Signature:</b>
countIf(): AggregateFunction;
<b>Returns:</b>
A new AggregateFunction representing the 'countIf' aggregation.
// Find the count of documents with a score greater than 90
field("score").greaterThan(90).countIf().as("highestScore");
Creates an expression that returns the catch argument if there is an error, else return the result of this expression.
<b>Signature:</b>
ifError(catchValue: BooleanExpression): BooleanExpression;
| Parameter | Type | Description |
|---|---|---|
| catchValue | BooleanExpression | The value that will be returned if this expression produces an error. |
<b>Returns:</b>
A new Expression representing the 'ifError' operation.
// Create an expression that protects against a divide by zero error
// but always returns a boolean expression.
constant(50).divide(field('length')).greaterThan(1).ifError(constant(false));
Creates an expression that returns the catch argument if there is an error, else return the result of this expression.
<b>Signature:</b>
ifError(catchValue: boolean): BooleanExpression;
| Parameter | Type | Description |
|---|---|---|
| catchValue | boolean | The value that will be returned if this expression produces an error. |
<b>Returns:</b>
A new Expression representing the 'ifError' operation.
// Create an expression that protects against a divide by zero error
// but always returns a boolean expression.
constant(50).divide(field('length')).greaterThan(1).ifError(false);
Creates an expression that returns the catch argument if there is an error, else return the result of this expression.
<b>Signature:</b>
ifError(catchValue: Expression): FunctionExpression;
| Parameter | Type | Description |
|---|---|---|
| catchValue | Expression | The value that will be returned if this expression produces an error. |
<b>Returns:</b>
A new Expression representing the 'ifError' operation.
// Create an expression that protects against a divide by zero error.
constant(50).divide(field('length')).greaterThan(1).ifError(constant(0));
Creates an expression that returns the catch argument if there is an error, else return the result of this expression.
<b>Signature:</b>
ifError(catchValue: unknown): FunctionExpression;
| Parameter | Type | Description |
|---|---|---|
| catchValue | unknown | The value that will be returned if this expression produces an error. |
<b>Returns:</b>
A new Expression representing the 'ifError' operation.
// Create an expression that protects against a divide by zero error.
constant(50).divide(field('length')).greaterThan(1).ifError(0);
Creates an expression that negates this boolean expression.
<b>Signature:</b>
not(): BooleanExpression;
<b>Returns:</b>
A new Expression representing the negated filter condition.
// Find documents where the 'tags' field does not contain 'completed'
field("tags").arrayContains("completed").not();