Back to Firebase Js Sdk

BooleanExpression class

docs-devsite/firestore_lite_pipelines.booleanexpression.md

12.12.17.8 KB
Original Source

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.

<b>Signature:</b>

typescript
export declare abstract class BooleanExpression extends Expression 

<b>Extends:</b> Expression

Methods

MethodModifiersDescription
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.

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<!-- -->.

<b>Signature:</b>

typescript
conditional(thenExpr: Expression, elseExpr: Expression): FunctionExpression;

Parameters

ParameterTypeDescription
thenExprExpressionThe expression to evaluate if the condition is true.
elseExprExpressionThe expression to evaluate if the condition is false.

<b>Returns:</b>

FunctionExpression

A new Expression 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.

<b>Signature:</b>

typescript
countIf(): AggregateFunction;

<b>Returns:</b>

AggregateFunction

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.

<b>Signature:</b>

typescript
ifError(catchValue: BooleanExpression): BooleanExpression;

Parameters

ParameterTypeDescription
catchValueBooleanExpressionThe value that will be returned if this expression produces an error.

<b>Returns:</b>

BooleanExpression

A new Expression 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.

<b>Signature:</b>

typescript
ifError(catchValue: boolean): BooleanExpression;

Parameters

ParameterTypeDescription
catchValuebooleanThe value that will be returned if this expression produces an error.

<b>Returns:</b>

BooleanExpression

A new Expression 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.

<b>Signature:</b>

typescript
ifError(catchValue: Expression): FunctionExpression;

Parameters

ParameterTypeDescription
catchValueExpressionThe value that will be returned if this expression produces an error.

<b>Returns:</b>

FunctionExpression

A new Expression 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.

<b>Signature:</b>

typescript
ifError(catchValue: unknown): FunctionExpression;

Parameters

ParameterTypeDescription
catchValueunknownThe value that will be returned if this expression produces an error.

<b>Returns:</b>

FunctionExpression

A new Expression 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.

<b>Signature:</b>

typescript
not(): BooleanExpression;

<b>Returns:</b>

BooleanExpression

A new Expression representing the negated filter condition.

Example

typescript
// Find documents where the 'tags' field does not contain 'completed'
field("tags").arrayContains("completed").not();