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 %} # BooleanExpression class An interface that represents a filter condition. Signature: ```typescript export declare abstract class BooleanExpression extends Expression ``` Extends: [Expression](./firestore_lite_pipelines.expression.md#expression_class) ## Methods | Method | Modifiers | Description | | --- | --- | --- | | [conditional(thenExpr, elseExpr)](./firestore_lite_pipelines.booleanexpression.md#booleanexpressionconditional) | | 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. | | [countIf()](./firestore_lite_pipelines.booleanexpression.md#booleanexpressioncountif) | | Creates an aggregation that finds the count of input documents satisfying this boolean expression. | | [ifError(catchValue)](./firestore_lite_pipelines.booleanexpression.md#booleanexpressioniferror) | | Creates an expression that returns the catch argument if there is an error, else return the result of this expression. | | [ifError(catchValue)](./firestore_lite_pipelines.booleanexpression.md#booleanexpressioniferror) | | Creates an expression that returns the catch argument if there is an error, else return the result of this expression. | | [ifError(catchValue)](./firestore_lite_pipelines.booleanexpression.md#booleanexpressioniferror) | | Creates an expression that returns the catch argument if there is an error, else return the result of this expression. | | [ifError(catchValue)](./firestore_lite_pipelines.booleanexpression.md#booleanexpressioniferror) | | Creates an expression that returns the catch argument if there is an error, else return the result of this expression. | | [not()](./firestore_lite_pipelines.booleanexpression.md#booleanexpressionnot) | | Creates an expression that negates this boolean expression. | ## BooleanExpression.conditional() 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`. Signature: ```typescript conditional(thenExpr: Expression, elseExpr: Expression): FunctionExpression; ``` #### Parameters | Parameter | Type | Description | | --- | --- | --- | | thenExpr | [Expression](./firestore_lite_pipelines.expression.md#expression_class) | The expression to evaluate if the condition is true. | | elseExpr | [Expression](./firestore_lite_pipelines.expression.md#expression_class) | The expression to evaluate if the condition is false. | Returns: [FunctionExpression](./firestore_lite_pipelines.functionexpression.md#functionexpression_class) A new [Expression](./firestore_pipelines.expression.md#expression_class) representing the conditional expression. ### Example ```typescript // If 'age' is greater than 18, return "Adult"; otherwise, return "Minor". field("age").greaterThanOrEqual(18).conditional(constant("Adult"), constant("Minor")); ``` ## BooleanExpression.countIf() Creates an aggregation that finds the count of input documents satisfying this boolean expression. Signature: ```typescript countIf(): AggregateFunction; ``` Returns: [AggregateFunction](./firestore_lite_pipelines.aggregatefunction.md#aggregatefunction_class) A new `AggregateFunction` representing the 'countIf' aggregation. ### Example ```typescript // Find the count of documents with a score greater than 90 field("score").greaterThan(90).countIf().as("highestScore"); ``` ## BooleanExpression.ifError() Creates an expression that returns the `catch` argument if there is an error, else return the result of this expression. Signature: ```typescript ifError(catchValue: BooleanExpression): BooleanExpression; ``` #### Parameters | Parameter | Type | Description | | --- | --- | --- | | catchValue | [BooleanExpression](./firestore_lite_pipelines.booleanexpression.md#booleanexpression_class) | The value that will be returned if this expression produces an error. | Returns: [BooleanExpression](./firestore_lite_pipelines.booleanexpression.md#booleanexpression_class) A new [Expression](./firestore_pipelines.expression.md#expression_class) representing the 'ifError' operation. ### Example ```typescript // 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)); ``` ## BooleanExpression.ifError() Creates an expression that returns the `catch` argument if there is an error, else return the result of this expression. Signature: ```typescript ifError(catchValue: boolean): BooleanExpression; ``` #### Parameters | Parameter | Type | Description | | --- | --- | --- | | catchValue | boolean | The value that will be returned if this expression produces an error. | Returns: [BooleanExpression](./firestore_lite_pipelines.booleanexpression.md#booleanexpression_class) A new [Expression](./firestore_pipelines.expression.md#expression_class) representing the 'ifError' operation. ### Example ```typescript // 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); ``` ## BooleanExpression.ifError() Creates an expression that returns the `catch` argument if there is an error, else return the result of this expression. Signature: ```typescript ifError(catchValue: Expression): FunctionExpression; ``` #### Parameters | Parameter | Type | Description | | --- | --- | --- | | catchValue | [Expression](./firestore_lite_pipelines.expression.md#expression_class) | The value that will be returned if this expression produces an error. | Returns: [FunctionExpression](./firestore_lite_pipelines.functionexpression.md#functionexpression_class) A new [Expression](./firestore_pipelines.expression.md#expression_class) representing the 'ifError' operation. ### Example ```typescript // Create an expression that protects against a divide by zero error. constant(50).divide(field('length')).greaterThan(1).ifError(constant(0)); ``` ## BooleanExpression.ifError() Creates an expression that returns the `catch` argument if there is an error, else return the result of this expression. Signature: ```typescript ifError(catchValue: unknown): FunctionExpression; ``` #### Parameters | Parameter | Type | Description | | --- | --- | --- | | catchValue | unknown | The value that will be returned if this expression produces an error. | Returns: [FunctionExpression](./firestore_lite_pipelines.functionexpression.md#functionexpression_class) A new [Expression](./firestore_pipelines.expression.md#expression_class) representing the 'ifError' operation. ### Example ```typescript // Create an expression that protects against a divide by zero error. constant(50).divide(field('length')).greaterThan(1).ifError(0); ``` ## BooleanExpression.not() Creates an expression that negates this boolean expression. Signature: ```typescript not(): BooleanExpression; ``` Returns: [BooleanExpression](./firestore_lite_pipelines.booleanexpression.md#booleanexpression_class) A new [Expression](./firestore_pipelines.expression.md#expression_class) representing the negated filter condition. ### Example ```typescript // Find documents where the 'tags' field does not contain 'completed' field("tags").arrayContains("completed").not(); ```