Back to Firebase Js Sdk

Expression class

docs-devsite/firestore_lite_pipelines.expression.md

12.12.1157.3 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 %}

Expression class

Represents an expression that can be evaluated to a value within the execution of a Pipeline<!-- -->.

Expressions are the building blocks for creating complex queries and transformations in Firestore pipelines. They can represent:

  • **Field references:** Access values from document fields. - **Literals:** Represent constant values (strings, numbers, booleans). - **Function calls:** Apply functions to one or more expressions.

The Expression class provides a fluent API for building expressions. You can chain together method calls to create complex expressions.

<b>Signature:</b>

typescript
export declare abstract class Expression 

Properties

PropertyModifiersTypeDescription
expressionTypeExpressionType

Methods

MethodModifiersDescription
abs()Creates an expression that computes the absolute value of a numeric value.
add(second)Creates an expression that adds this expression to another expression.
arrayAgg()Creates an aggregation that collects all values of an expression across multiple stage inputs into an array.
arrayAggDistinct()Creates an aggregation that collects all distinct values of an expression across multiple stage inputs into an array.
arrayConcat(secondArray, otherArrays)Creates an expression that concatenates an array expression with one or more other arrays.
arrayContains(expression)Creates an expression that checks if an array contains a specific element.
arrayContains(value)Creates an expression that checks if an array contains a specific value.
arrayContainsAll(values)Creates an expression that checks if an array contains all the specified elements.
arrayContainsAll(arrayExpression)Creates an expression that checks if an array contains all the specified elements.
arrayContainsAny(values)Creates an expression that checks if an array contains any of the specified elements.
arrayContainsAny(arrayExpression)Creates an expression that checks if an array contains any of the specified elements.
arrayFilter(alias, filter)Filters the array using a provided alias and predicate expression.
arrayFirst()Returns the first element of the array.
arrayFirstN(n)Returns the first <code>n</code> elements of the array.
arrayFirstN(n)Returns the first <code>n</code> elements of the array.
arrayGet(offset)Creates an expression that indexes into an array from the beginning or end and returns the element. If the offset exceeds the array length, an error is returned. A negative offset, starts from the end.
arrayGet(offsetExpr)Creates an expression that indexes into an array from the beginning or end and returns the element. If the offset exceeds the array length, an error is returned. A negative offset, starts from the end.
arrayIndexOf(search)Returns the first index of the search value in the array, or -1 if not found.
arrayIndexOf(search)Returns the first index of the search value in the array, or -1 if not found.
arrayIndexOfAll(search)Returns all indices of the search value in the array.
arrayIndexOfAll(search)Returns all indices of the search value in the array.
arrayLast()Returns the last element of the array.
arrayLastIndexOf(search)Returns the last index of the search value in the array, or -1 if not found.
arrayLastIndexOf(search)Returns the last index of the search value in the array, or -1 if not found.
arrayLastN(n)Returns the last <code>n</code> elements of the array.
arrayLastN(n)Returns the last <code>n</code> elements of the array.
arrayLength()Creates an expression that calculates the length of an array.
arrayMaximum()Returns the maximum value in the array.
arrayMaximumN(n)Returns the largest <code>n</code> elements of the array.<!-- -->Note: Returns the n largest non-null elements in the array, in descending order. This does not use a stable sort, meaning the order of equivalent elements is undefined.
arrayMaximumN(n)Returns the largest <code>n</code> elements of the array.<!-- -->Note: Returns the n largest non-null elements in the array, in descending order. This does not use a stable sort, meaning the order of equivalent elements is undefined.
arrayMinimum()Returns the minimum value in the array.
arrayMinimumN(n)Returns the smallest <code>n</code> elements of the array.<!-- -->Note: Returns the n smallest non-null elements in the array, in ascending order. This does not use a stable sort, meaning the order of equivalent elements is undefined.
arrayMinimumN(n)Returns the smallest <code>n</code> elements of the array.<!-- -->Note: Returns the n smallest non-null elements in the array, in ascending order. This does not use a stable sort, meaning the order of equivalent elements is undefined.
arrayReverse()Creates an expression that reverses an array.
arraySlice(offset, length)Returns a subset of the array.
arraySum()Creates an expression that computes the sum of the elements in an array.
arrayTransform(elementAlias, transform)Creates an expression that applies a provided transformation to each element in an array.
arrayTransformWithIndex(elementAlias, indexAlias, transform)Creates an expression that applies a provided transformation to each element in an array, providing the element's index to the transformation expression.
as(name)Assigns an alias to this expression.<!-- -->Aliases are useful for renaming fields in the output of a stage or for giving meaningful names to calculated values.
asBoolean()Wraps the expression in a [BooleanExpression].
ascending()Creates an Ordering that sorts documents in ascending order based on this expression.
average()Creates an aggregation that calculates the average (mean) of a numeric field across multiple stage inputs.
byteLength()Creates an expression that calculates the length of this string expression in bytes.
ceil()Creates an expression that computes the ceiling of a numeric value.
charLength()Creates an expression that calculates the character length of a string in UTF-8.
coalesce(replacement, others)Creates an expression that returns the first non-null, non-absent argument, without evaluating the rest of the arguments. When all arguments are null or absent, returns the last argument.
collectionId()Creates an expression that returns the collection ID from a path.
concat(second, others)Creates an expression that concatenates expression results together.
cosineDistance(vectorExpression)Calculates the cosine distance between two vectors.
cosineDistance(vector)Calculates the Cosine distance between two vectors.
count()Creates an aggregation that counts the number of stage inputs with valid evaluations of the expression or field.
countDistinct()Creates an aggregation that counts the number of distinct values of the expression or field.
descending()Creates an Ordering that sorts documents in descending order based on this expression.
divide(divisor)Creates an expression that divides this expression by another expression.
divide(divisor)Creates an expression that divides this expression by a constant value.
documentId()Creates an expression that returns the document ID from a path.
dotProduct(vectorExpression)Calculates the dot product between two vectors.
dotProduct(vector)Calculates the dot product between two vectors.
endsWith(suffix)Creates an expression that checks if a string ends with a given postfix.
endsWith(suffix)Creates an expression that checks if a string ends with a given postfix (represented as an expression).
equal(expression)Creates an expression that checks if this expression is equal to another expression.
equal(value)Creates an expression that checks if this expression is equal to a constant value.
equalAny(values)Creates an expression that checks if this expression is equal to any of the provided values or expressions.
equalAny(arrayExpression)Creates an expression that checks if this expression is equal to any of the provided values or expressions.
euclideanDistance(vectorExpression)Calculates the Euclidean distance between two vectors.
euclideanDistance(vector)Calculates the Euclidean distance between two vectors.
exists()Creates an expression that checks if a field exists in the document.
exp()Creates an expression that computes e to the power of this expression.
first()Creates an aggregation that finds the first value of an expression across multiple stage inputs.
floor()Creates an expression that computes the floor of a numeric value.
getField(key)Creates an expression that returns the value of a field from the document that results from the evaluation of this expression.
greaterThan(expression)Creates an expression that checks if this expression is greater than another expression.
greaterThan(value)Creates an expression that checks if this expression is greater than a constant value.
greaterThanOrEqual(expression)Creates an expression that checks if this expression is greater than or equal to another expression.
greaterThanOrEqual(value)Creates an expression that checks if this expression is greater than or equal to a constant value.
ifAbsent(elseValue)Creates an expression that returns the <code>elseValue</code> argument if this expression results in an absent value, else return the result of this expression evaluation.
ifAbsent(elseExpression)Creates an expression that returns the <code>elseValue</code> argument if this expression results in an absent value, else return the result of this expression evaluation.
ifError(catchExpr)Creates an expression that returns the result of the <code>catchExpr</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.
ifNull(elseExpression)Creates an expression that returns the <code>elseValue</code> argument if this expression evaluates to null, else return the result of this expression evaluation.
ifNull(elseValue)Creates an expression that returns the <code>elseValue</code> argument if this expression evaluates to null, else return the result of this expression evaluation.
isAbsent()Creates an expression that returns <code>true</code> if the result of this expression is absent. Otherwise, returns <code>false</code> even if the value is <code>null</code>.
isError()Creates an expression that checks if a given expression produces an error.
isType(type)Creates an expression that checks if the result of this expression is of the given type.
join(delimiterExpression)Creates an expression that joins the elements of an array into a string.
join(delimiter)Creates an expression that joins the elements of an array field into a string.
last()Creates an aggregation that finds the last value of an expression across multiple stage inputs.
length()Creates an expression that calculates the length of a string, array, map, vector, or bytes.
lessThan(experession)Creates an expression that checks if this expression is less than another expression.
lessThan(value)Creates an expression that checks if this expression is less than a constant value.
lessThanOrEqual(expression)Creates an expression that checks if this expression is less than or equal to another expression.
lessThanOrEqual(value)Creates an expression that checks if this expression is less than or equal to a constant value.
like(pattern)Creates an expression that performs a case-sensitive string comparison.
like(pattern)Creates an expression that performs a case-sensitive string comparison.
ln()Creates an expression that computes the natural logarithm of a numeric value.
log10()Creates an expression that computes the base-10 logarithm of a numeric value.
logicalMaximum(second, others)Creates an expression that returns the larger value between this expression and another expression, based on Firestore's value type ordering.
logicalMinimum(second, others)Creates an expression that returns the smaller value between this expression and another expression, based on Firestore's value type ordering.
ltrim(valueToTrim)Trims whitespace or a specified set of characters/bytes from the beginning of a string or byte array.
mapEntries()Creates an expression that returns the entries of a map as an array of maps, where each map contains a <code>"k"</code> property for the key and a <code>"v"</code> property for the value. For example: <code>[{ k: "key1", v: "value1" }, ...]</code>.
mapGet(subfield)Accesses a value from a map (object) field using the provided key.
mapKeys()Creates an expression that returns the keys of a map.
mapMerge(secondMap, otherMaps)Creates an expression that merges multiple map values.
mapRemove(key)Creates an expression that removes a key from the map produced by evaluating this expression.
mapRemove(keyExpr)Creates an expression that removes a key from the map produced by evaluating this expression.
mapSet(key, value, moreKeyValues)Creates an expression that returns a new map with the specified entries added or updated.
mapValues()Creates an expression that returns the values of a map.
maximum()Creates an aggregation that finds the maximum value of a field across multiple stage inputs.
minimum()Creates an aggregation that finds the minimum value of a field across multiple stage inputs.
mod(expression)Creates an expression that calculates the modulo (remainder) of dividing this expression by another expression.
mod(value)Creates an expression that calculates the modulo (remainder) of dividing this expression by a constant value.
multiply(second)Creates an expression that multiplies this expression by another expression.
notEqual(expression)Creates an expression that checks if this expression is not equal to another expression.
notEqual(value)Creates an expression that checks if this expression is not equal to a constant value.
notEqualAny(values)Creates an expression that checks if this expression is not equal to any of the provided values or expressions.
notEqualAny(arrayExpression)Creates an expression that checks if this expression is not equal to any of the values in the evaluated expression.
parent()Creates an expression that returns the parent document reference of a document reference.
pow(exponent)Creates an expression that returns the value of this expression raised to the power of another expression.
pow(exponent)Creates an expression that returns the value of this expression raised to the power of a constant value.
regexContains(pattern)Creates an expression that checks if a string contains a specified regular expression as a substring.
regexContains(pattern)Creates an expression that checks if a string contains a specified regular expression as a substring.
regexFind(pattern)Creates an expression that returns the first substring of a string expression that matches a specified regular expression.<!-- -->This expression uses the RE2 regular expression syntax.
regexFind(pattern)Creates an expression that returns the first substring of a string expression that matches a specified regular expression.<!-- -->This expression uses the RE2 regular expression syntax.
regexFindAll(pattern)Creates an expression that evaluates to a list of all substrings in this string expression that match a specified regular expression.<!-- -->This expression uses the RE2 regular expression syntax.
regexFindAll(pattern)Creates an expression that evaluates to a list of all substrings in this string expression that match a specified regular expression.<!-- -->This expression uses the RE2 regular expression syntax.
regexMatch(pattern)Creates an expression that checks if a string matches a specified regular expression.
regexMatch(pattern)Creates an expression that checks if a string matches a specified regular expression.
reverse()Creates an expression that reverses this string expression.
round()Creates an expression that rounds a numeric value to the nearest whole number.
round(decimalPlaces)Creates an expression that rounds a numeric value to the specified number of decimal places.
round(decimalPlaces)Creates an expression that rounds a numeric value to the specified number of decimal places.
rtrim(valueToTrim)Trims whitespace or a specified set of characters/bytes from the end of a string or byte array.
split(delimiter)Creates an expression that splits the result of this expression into an array of substrings based on the provided delimiter.
split(delimiter)Creates an expression that splits the result of this expression into an array of substrings based on the provided delimiter.
sqrt()Creates an expression that computes the square root of a numeric value.
startsWith(prefix)Creates an expression that checks if a string starts with a given prefix.
startsWith(prefix)Creates an expression that checks if a string starts with a given prefix (represented as an expression).
stringConcat(secondString, otherStrings)Creates an expression that concatenates string expressions together.
stringContains(substring)Creates an expression that checks if a string contains a specified substring.
stringContains(expr)Creates an expression that checks if a string contains the string represented by another expression.
stringIndexOf(search)Creates an expression that finds the index of the first occurrence of a substring or byte sequence.
stringRepeat(repetitions)Creates an expression that repeats a string or byte array a specified number of times.
stringReplaceAll(find, replacement)Creates an expression that replaces all occurrences of a substring or byte sequence with a replacement.
stringReplaceOne(find, replacement)Creates an expression that replaces the first occurrence of a substring or byte sequence with a replacement.
stringReverse()Creates an expression that reverses a string.
substring(position, length)Creates an expression that returns a substring of the results of this expression.
substring(position, length)Creates an expression that returns a substring of the results of this expression.
subtract(subtrahend)Creates an expression that subtracts another expression from this expression.
subtract(subtrahend)Creates an expression that subtracts a constant value from this expression.
sum()Creates an aggregation that calculates the sum of a numeric field across multiple stage inputs.
timestampAdd(unit, amount)Creates an expression that adds a specified amount of time to this timestamp expression.
timestampAdd(unit, amount)Creates an expression that adds a specified amount of time to this timestamp expression.
timestampDiff(start, unit)Creates an expression that calculates the difference between this timestamp and another timestamp.
timestampDiff(start, unit)Creates an expression that calculates the difference between this timestamp and another timestamp.
timestampExtract(part, timezone)Creates an expression that extracts a specified part from this timestamp expression.
timestampExtract(part, timezone)Creates an expression that extracts a specified part from this timestamp expression.
timestampSubtract(unit, amount)Creates an expression that subtracts a specified amount of time from this timestamp expression.
timestampSubtract(unit, amount)Creates an expression that subtracts a specified amount of time from this timestamp expression.
timestampToUnixMicros()Creates an expression that converts this timestamp expression to the number of microseconds since the Unix epoch (1970-01-01 00:00:00 UTC).
timestampToUnixMillis()Creates an expression that converts this timestamp expression to the number of milliseconds since the Unix epoch (1970-01-01 00:00:00 UTC).
timestampToUnixSeconds()Creates an expression that converts this timestamp expression to the number of seconds since the Unix epoch (1970-01-01 00:00:00 UTC).
timestampTruncate(granularity, timezone)Creates an expression that truncates a timestamp to a specified granularity.
timestampTruncate(granularity, timezone)Creates an expression that truncates a timestamp to a specified granularity.
toLower()Creates an expression that converts a string to lowercase.
toUpper()Creates an expression that converts a string to uppercase.
trim(valueToTrim)Creates an expression that removes leading and trailing characters from a string or byte array.
trunc()Creates an expression that truncates the numeric value to an integer.
trunc(decimalPlaces)Creates an expression that truncates a numeric value to the specified number of decimal places.
trunc(decimalPlaces)Creates an expression that truncates a numeric value to the specified number of decimal places.
type()Creates an expression that returns the data type of this expression's result, as a string.
unixMicrosToTimestamp()Creates an expression that interprets this expression as the number of microseconds since the Unix epoch (1970-01-01 00:00:00 UTC) and returns a timestamp.
unixMillisToTimestamp()Creates an expression that interprets this expression as the number of milliseconds since the Unix epoch (1970-01-01 00:00:00 UTC) and returns a timestamp.
unixSecondsToTimestamp()Creates an expression that interprets this expression as the number of seconds since the Unix epoch (1970-01-01 00:00:00 UTC) and returns a timestamp.
vectorLength()Creates an expression that calculates the length (number of dimensions) of this Firestore Vector expression.

Expression.expressionType

<b>Signature:</b>

typescript
abstract readonly expressionType: ExpressionType;

Expression.abs()

Creates an expression that computes the absolute value of a numeric value.

<b>Signature:</b>

typescript
abs(): FunctionExpression;

<b>Returns:</b>

FunctionExpression

A new Expression representing the absolute value of the numeric value.

Example

typescript
// Compute the absolute value of the 'price' field.
field("price").abs();

Expression.add()

Creates an expression that adds this expression to another expression.

<b>Signature:</b>

typescript
add(second: Expression | unknown): FunctionExpression;

Parameters

ParameterTypeDescription
secondExpression | unknownThe expression or literal to add to this expression.

<b>Returns:</b>

FunctionExpression

A new Expression representing the addition operation.

Example

typescript
// Add the value of the 'quantity' field and the 'reserve' field.
field("quantity").add(field("reserve"));

Expression.arrayAgg()

Creates an aggregation that collects all values of an expression across multiple stage inputs into an array.

If the expression resolves to an absent value, it is converted to null<!-- -->. The order of elements in the output array is not stable and shouldn't be relied upon.

<b>Signature:</b>

typescript
arrayAgg(): AggregateFunction;

<b>Returns:</b>

AggregateFunction

A new AggregateFunction representing the 'array_agg' aggregation.

Example

typescript
// Collect all tags from books into an array
field("tags").arrayAgg().as("allTags");

Expression.arrayAggDistinct()

Creates an aggregation that collects all distinct values of an expression across multiple stage inputs into an array.

If the expression resolves to an absent value, it is converted to null<!-- -->. The order of elements in the output array is not stable and shouldn't be relied upon.

<b>Signature:</b>

typescript
arrayAggDistinct(): AggregateFunction;

<b>Returns:</b>

AggregateFunction

A new AggregateFunction representing the 'array_agg_distinct' aggregation.

Example

typescript
// Collect all distinct tags from books into an array
field("tags").arrayAggDistinct().as("allDistinctTags");

Expression.arrayConcat()

Creates an expression that concatenates an array expression with one or more other arrays.

<b>Signature:</b>

typescript
arrayConcat(secondArray: Expression | unknown[], ...otherArrays: Array<Expression | unknown[]>): FunctionExpression;

Parameters

ParameterTypeDescription
secondArrayExpression | unknown[]Second array expression or array literal to concatenate.
otherArraysArray<Expression | unknown[]>Optional additional array expressions or array literals to concatenate.

<b>Returns:</b>

FunctionExpression

A new Expression representing the concatenated array.

Example

typescript
// Combine the 'items' array with another array field.
field("items").arrayConcat(field("otherItems"));

Expression.arrayContains()

Creates an expression that checks if an array contains a specific element.

<b>Signature:</b>

typescript
arrayContains(expression: Expression): BooleanExpression;

Parameters

ParameterTypeDescription
expressionExpressionThe element to search for in the array.

<b>Returns:</b>

BooleanExpression

A new Expression representing the 'array_contains' comparison.

Example

typescript
// Check if the 'sizes' array contains the value from the 'selectedSize' field
field("sizes").arrayContains(field("selectedSize"));

Expression.arrayContains()

Creates an expression that checks if an array contains a specific value.

<b>Signature:</b>

typescript
arrayContains(value: unknown): BooleanExpression;

Parameters

ParameterTypeDescription
valueunknownThe element to search for in the array.

<b>Returns:</b>

BooleanExpression

A new Expression representing the 'array_contains' comparison.

Example

typescript
// Check if the 'colors' array contains "red"
field("colors").arrayContains("red");

Expression.arrayContainsAll()

Creates an expression that checks if an array contains all the specified elements.

<b>Signature:</b>

typescript
arrayContainsAll(values: Array<Expression | unknown>): BooleanExpression;

Parameters

ParameterTypeDescription
valuesArray<Expression | unknown>The elements to check for in the array.

<b>Returns:</b>

BooleanExpression

A new Expression representing the 'array_contains_all' comparison.

Example

typescript
// Check if the 'tags' array contains both the value in field "tag1" and the literal value "tag2"
field("tags").arrayContainsAll([field("tag1"), "tag2"]);

Expression.arrayContainsAll()

Creates an expression that checks if an array contains all the specified elements.

<b>Signature:</b>

typescript
arrayContainsAll(arrayExpression: Expression): BooleanExpression;

Parameters

ParameterTypeDescription
arrayExpressionExpressionThe elements to check for in the array.

<b>Returns:</b>

BooleanExpression

A new Expression representing the 'array_contains_all' comparison.

Example

typescript
// Check if the 'tags' array contains both of the values from field "tag1" and the literal value "tag2"
field("tags").arrayContainsAll(array([field("tag1"), "tag2"]));

Expression.arrayContainsAny()

Creates an expression that checks if an array contains any of the specified elements.

<b>Signature:</b>

typescript
arrayContainsAny(values: Array<Expression | unknown>): BooleanExpression;

Parameters

ParameterTypeDescription
valuesArray<Expression | unknown>The elements to check for in the array.

<b>Returns:</b>

BooleanExpression

A new Expression representing the 'array_contains_any' comparison.

Example

typescript
// Check if the 'categories' array contains either values from field "cate1" or "cate2"
field("categories").arrayContainsAny([field("cate1"), field("cate2")]);

Expression.arrayContainsAny()

Creates an expression that checks if an array contains any of the specified elements.

<b>Signature:</b>

typescript
arrayContainsAny(arrayExpression: Expression): BooleanExpression;

Parameters

ParameterTypeDescription
arrayExpressionExpressionThe elements to check for in the array.

<b>Returns:</b>

BooleanExpression

A new Expression representing the 'array_contains_any' comparison.

Example

typescript
// Check if the 'groups' array contains either the value from the 'userGroup' field
// or the value "guest"
field("groups").arrayContainsAny(array([field("userGroup"), "guest"]));

Expression.arrayFilter()

Filters the array using a provided alias and predicate expression.

<b>Signature:</b>

typescript
arrayFilter(alias: string, filter: BooleanExpression): FunctionExpression;

Parameters

ParameterTypeDescription
aliasstringThe variable name to use for each element.
filterBooleanExpressionThe predicate boolean expression to filter by.

<b>Returns:</b>

FunctionExpression

A new Expression representing the filtered array.

Example

typescript
// Filter the 'items' array to only include those where the 'price' is greater than 10
field("items").arrayFilter('item', greaterThan(variable('item.price'), 10));

Expression.arrayFirst()

Returns the first element of the array.

<b>Signature:</b>

typescript
arrayFirst(): FunctionExpression;

<b>Returns:</b>

FunctionExpression

A new Expression representing the first element.

Example

typescript
// Get the first element of the 'myArray' field.
field("myArray").arrayFirst();

Expression.arrayFirstN()

Returns the first n elements of the array.

<b>Signature:</b>

typescript
arrayFirstN(n: number): FunctionExpression;

Parameters

ParameterTypeDescription
nnumberThe number of elements to return.

<b>Returns:</b>

FunctionExpression

A new Expression representing the first n elements.

Example

typescript
// Get the first 3 elements of the 'myArray' field.
field("myArray").arrayFirstN(3);

Expression.arrayFirstN()

Returns the first n elements of the array.

<b>Signature:</b>

typescript
arrayFirstN(n: Expression): FunctionExpression;

Parameters

ParameterTypeDescription
nExpressionAn expression evaluating to the number of elements to return.

<b>Returns:</b>

FunctionExpression

A new Expression representing the first n elements.

Example

typescript
// Get the first n elements of the 'myArray' field.
field("myArray").arrayFirstN(field("count"));

Expression.arrayGet()

Creates an expression that indexes into an array from the beginning or end and returns the element. If the offset exceeds the array length, an error is returned. A negative offset, starts from the end.

<b>Signature:</b>

typescript
arrayGet(offset: number): FunctionExpression;

Parameters

ParameterTypeDescription
offsetnumberThe index of the element to return.

<b>Returns:</b>

FunctionExpression

A new Expression representing the 'arrayGet' operation.

Example

typescript
// Return the value in the 'tags' field array at index `1`.
field('tags').arrayGet(1);

Expression.arrayGet()

Creates an expression that indexes into an array from the beginning or end and returns the element. If the offset exceeds the array length, an error is returned. A negative offset, starts from the end.

<b>Signature:</b>

typescript
arrayGet(offsetExpr: Expression): FunctionExpression;

Parameters

ParameterTypeDescription
offsetExprExpressionAn <code>Expression</code> evaluating to the index of the element to return.

<b>Returns:</b>

FunctionExpression

A new Expression representing the 'arrayGet' operation.

Example

typescript
// Return the value in the tags field array at index specified by field
// 'favoriteTag'.
field('tags').arrayGet(field('favoriteTag'));

Expression.arrayIndexOf()

Returns the first index of the search value in the array, or -1 if not found.

<b>Signature:</b>

typescript
arrayIndexOf(search: unknown): FunctionExpression;

Parameters

ParameterTypeDescription
searchunknownThe value to search for.

<b>Returns:</b>

FunctionExpression

A new Expression representing the index.

Example

typescript
// Get the first index of the value 3 in the 'myArray' field.
field("myArray").arrayIndexOf(3);

Expression.arrayIndexOf()

Returns the first index of the search value in the array, or -1 if not found.

<b>Signature:</b>

typescript
arrayIndexOf(search: Expression): FunctionExpression;

Parameters

ParameterTypeDescription
searchExpressionAn expression evaluating to the value to search for.

<b>Returns:</b>

FunctionExpression

A new Expression representing the index.

Example

typescript
// Get the first index of the value in 'searchVal' field in the 'myArray' field.
field("myArray").arrayIndexOf(field("searchVal"));

Expression.arrayIndexOfAll()

Returns all indices of the search value in the array.

<b>Signature:</b>

typescript
arrayIndexOfAll(search: unknown): FunctionExpression;

Parameters

ParameterTypeDescription
searchunknownThe value to search for.

<b>Returns:</b>

FunctionExpression

A new Expression representing the indices.

Example

typescript
// Get all indices of the value 3 in the 'myArray' field.
field("myArray").arrayIndexOfAll(3);

Expression.arrayIndexOfAll()

Returns all indices of the search value in the array.

<b>Signature:</b>

typescript
arrayIndexOfAll(search: Expression): FunctionExpression;

Parameters

ParameterTypeDescription
searchExpressionAn expression evaluating to the value to search for.

<b>Returns:</b>

FunctionExpression

A new Expression representing the indices.

Example

typescript
// Get all indices of the value in 'searchVal' field in the 'myArray' field.
field("myArray").arrayIndexOfAll(field("searchVal"));

Expression.arrayLast()

Returns the last element of the array.

<b>Signature:</b>

typescript
arrayLast(): FunctionExpression;

<b>Returns:</b>

FunctionExpression

A new Expression representing the last element.

Example

typescript
// Get the last element of the 'myArray' field.
field("myArray").arrayLast();

Expression.arrayLastIndexOf()

Returns the last index of the search value in the array, or -1 if not found.

<b>Signature:</b>

typescript
arrayLastIndexOf(search: unknown): FunctionExpression;

Parameters

ParameterTypeDescription
searchunknownThe value to search for.

<b>Returns:</b>

FunctionExpression

A new Expression representing the index.

Example

typescript
// Get the last index of the value 3 in the 'myArray' field.
field("myArray").arrayLastIndexOf(3);

Expression.arrayLastIndexOf()

Returns the last index of the search value in the array, or -1 if not found.

<b>Signature:</b>

typescript
arrayLastIndexOf(search: Expression): FunctionExpression;

Parameters

ParameterTypeDescription
searchExpressionAn expression evaluating to the value to search for.

<b>Returns:</b>

FunctionExpression

A new Expression representing the index.

Example

typescript
// Get the last index of the value in 'searchVal' field in the 'myArray' field.
field("myArray").arrayLastIndexOf(field("searchVal"));

Expression.arrayLastN()

Returns the last n elements of the array.

<b>Signature:</b>

typescript
arrayLastN(n: number): FunctionExpression;

Parameters

ParameterTypeDescription
nnumberThe number of elements to return.

<b>Returns:</b>

FunctionExpression

A new Expression representing the last n elements.

Example

typescript
// Get the last 3 elements of the 'myArray' field.
field("myArray").arrayLastN(3);

Expression.arrayLastN()

Returns the last n elements of the array.

<b>Signature:</b>

typescript
arrayLastN(n: Expression): FunctionExpression;

Parameters

ParameterTypeDescription
nExpressionAn expression evaluating to the number of elements to return.

<b>Returns:</b>

FunctionExpression

A new Expression representing the last n elements.

Example

typescript
// Get the last n elements of the 'myArray' field.
field("myArray").arrayLastN(field("count"));

Expression.arrayLength()

Creates an expression that calculates the length of an array.

<b>Signature:</b>

typescript
arrayLength(): FunctionExpression;

<b>Returns:</b>

FunctionExpression

A new Expression representing the length of the array.

Example

typescript
// Get the number of items in the 'cart' array
field("cart").arrayLength();

Expression.arrayMaximum()

Returns the maximum value in the array.

<b>Signature:</b>

typescript
arrayMaximum(): FunctionExpression;

<b>Returns:</b>

FunctionExpression

A new Expression representing the maximum value.

Example

typescript
// Get the maximum value of the 'myArray' field.
field("myArray").arrayMaximum();

Expression.arrayMaximumN()

Returns the largest n elements of the array.

Note: Returns the n largest non-null elements in the array, in descending order. This does not use a stable sort, meaning the order of equivalent elements is undefined.

<b>Signature:</b>

typescript
arrayMaximumN(n: number): FunctionExpression;

Parameters

ParameterTypeDescription
nnumberThe number of elements to return.

<b>Returns:</b>

FunctionExpression

A new Expression representing the largest n elements.

Example

typescript
// Get the largest 3 elements of the 'myArray' field.
field("myArray").arrayMaximumN(3);

Expression.arrayMaximumN()

Returns the largest n elements of the array.

Note: Returns the n largest non-null elements in the array, in descending order. This does not use a stable sort, meaning the order of equivalent elements is undefined.

<b>Signature:</b>

typescript
arrayMaximumN(n: Expression): FunctionExpression;

Parameters

ParameterTypeDescription
nExpressionAn expression evaluating to the number of elements to return.

<b>Returns:</b>

FunctionExpression

A new Expression representing the largest n elements.

Example

typescript
// Get the largest n elements of the 'myArray' field.
field("myArray").arrayMaximumN(field("count"));

Expression.arrayMinimum()

Returns the minimum value in the array.

<b>Signature:</b>

typescript
arrayMinimum(): FunctionExpression;

<b>Returns:</b>

FunctionExpression

A new Expression representing the minimum value.

Example

typescript
// Get the minimum value of the 'myArray' field.
field("myArray").arrayMinimum();

Expression.arrayMinimumN()

Returns the smallest n elements of the array.

Note: Returns the n smallest non-null elements in the array, in ascending order. This does not use a stable sort, meaning the order of equivalent elements is undefined.

<b>Signature:</b>

typescript
arrayMinimumN(n: number): FunctionExpression;

Parameters

ParameterTypeDescription
nnumberThe number of elements to return.

<b>Returns:</b>

FunctionExpression

A new Expression representing the smallest n elements.

Example

typescript
// Get the smallest 3 elements of the 'myArray' field.
field("myArray").arrayMinimumN(3);

Expression.arrayMinimumN()

Returns the smallest n elements of the array.

Note: Returns the n smallest non-null elements in the array, in ascending order. This does not use a stable sort, meaning the order of equivalent elements is undefined.

<b>Signature:</b>

typescript
arrayMinimumN(n: Expression): FunctionExpression;

Parameters

ParameterTypeDescription
nExpressionAn expression evaluating to the number of elements to return.

<b>Returns:</b>

FunctionExpression

A new Expression representing the smallest n elements.

Example

typescript
// Get the smallest n elements of the 'myArray' field.
field("myArray").arrayMinimumN(field("count"));

Expression.arrayReverse()

Creates an expression that reverses an array.

<b>Signature:</b>

typescript
arrayReverse(): FunctionExpression;

<b>Returns:</b>

FunctionExpression

A new Expression representing the reversed array.

Example

typescript
// Reverse the value of the 'myArray' field.
field("myArray").arrayReverse();

Expression.arraySlice()

Returns a subset of the array.

<b>Signature:</b>

typescript
arraySlice(offset: number | Expression, length?: number | Expression): FunctionExpression;

Parameters

ParameterTypeDescription
offsetnumber | ExpressionThe starting offset.
lengthnumber | ExpressionThe optional length of the slice.

<b>Returns:</b>

FunctionExpression

A new Expression representing the sliced array.

Example

typescript
// Get 5 elements from the 'items' array starting from index 2
field("items").arraySlice(2, 5);

// Get n number of elements from the 'items' array starting from index 2
field("items").arraySlice(2, field("count"));

Expression.arraySum()

Creates an expression that computes the sum of the elements in an array.

<b>Signature:</b>

typescript
arraySum(): FunctionExpression;

<b>Returns:</b>

FunctionExpression

A new Expression representing the sum of the elements in the array.

Example

typescript
// Compute the sum of the elements in the 'scores' field.
field("scores").arraySum();

Expression.arrayTransform()

Creates an expression that applies a provided transformation to each element in an array.

<b>Signature:</b>

typescript
arrayTransform(elementAlias: string, transform: Expression): FunctionExpression;

Parameters

ParameterTypeDescription
elementAliasstringThe variable name to use for each element.
transformExpressionThe lambda expression used to transform the elements.

<b>Returns:</b>

FunctionExpression

A new Expression representing the arrayTransform operation.

Example

typescript
// Transform the 'scores' array by multiplying each score by 10
field("scores").arrayTransform("score", multiply(variable("score"), 10));

Expression.arrayTransformWithIndex()

Creates an expression that applies a provided transformation to each element in an array, providing the element's index to the transformation expression.

<b>Signature:</b>

typescript
arrayTransformWithIndex(elementAlias: string, indexAlias: string, transform: Expression): FunctionExpression;

Parameters

ParameterTypeDescription
elementAliasstringThe variable name to use for each element.
indexAliasstringThe variable name to use for the current index.
transformExpressionThe lambda expression used to transform the elements.

<b>Returns:</b>

FunctionExpression

A new Expression representing the arrayTransformWithIndex operation.

Example

typescript
// Transform the 'scores' array by adding the index to each score
field("scores").arrayTransformWithIndex("score", "i", add(variable("score"), variable("i")));

Expression.as()

Assigns an alias to this expression.

Aliases are useful for renaming fields in the output of a stage or for giving meaningful names to calculated values.

<b>Signature:</b>

typescript
as(name: string): AliasedExpression;

Parameters

ParameterTypeDescription
namestringThe alias to assign to this expression.

<b>Returns:</b>

AliasedExpression

A new AliasedExpression that wraps this expression and associates it with the provided alias.

Example

typescript
// Calculate the total price and assign it the alias "totalPrice" and add it to the output.
firestore.pipeline().collection("items")
  .addFields(field("price").multiply(field("quantity")).as("totalPrice"));

Expression.asBoolean()

Wraps the expression in a [BooleanExpression].

<b>Signature:</b>

typescript
asBoolean(): BooleanExpression;

<b>Returns:</b>

BooleanExpression

A [BooleanExpression] representing the same expression.

Expression.ascending()

Creates an Ordering that sorts documents in ascending order based on this expression.

<b>Signature:</b>

typescript
ascending(): Ordering;

<b>Returns:</b>

Ordering

A new Ordering for ascending sorting.

Example

typescript
// Sort documents by the 'name' field in ascending order
firestore.pipeline().collection("users")
  .sort(field("name").ascending());

Expression.average()

Creates an aggregation that calculates the average (mean) of a numeric field across multiple stage inputs.

<b>Signature:</b>

typescript
average(): AggregateFunction;

<b>Returns:</b>

AggregateFunction

A new AggregateFunction representing the 'average' aggregation.

Example

typescript
// Calculate the average age of users
field("age").average().as("averageAge");

Expression.byteLength()

Creates an expression that calculates the length of this string expression in bytes.

<b>Signature:</b>

typescript
byteLength(): FunctionExpression;

<b>Returns:</b>

FunctionExpression

A new Expression representing the length of the string in bytes.

Example

typescript
// Calculate the length of the 'myString' field in bytes.
field("myString").byteLength();

Expression.ceil()

Creates an expression that computes the ceiling of a numeric value.

<b>Signature:</b>

typescript
ceil(): FunctionExpression;

<b>Returns:</b>

FunctionExpression

A new Expression representing the ceiling of the numeric value.

Example

typescript
// Compute the ceiling of the 'price' field.
field("price").ceil();

Expression.charLength()

Creates an expression that calculates the character length of a string in UTF-8.

<b>Signature:</b>

typescript
charLength(): FunctionExpression;

<b>Returns:</b>

FunctionExpression

A new Expression representing the length of the string.

Example

typescript
// Get the character length of the 'name' field in its UTF-8 form.
field("name").charLength();

Expression.coalesce()

Creates an expression that returns the first non-null, non-absent argument, without evaluating the rest of the arguments. When all arguments are null or absent, returns the last argument.

<b>Signature:</b>

typescript
coalesce(replacement: Expression | unknown, ...others: Array<Expression | unknown>): FunctionExpression;

Parameters

ParameterTypeDescription
replacementExpression | unknownThe value to use if this expression evaluates to null.
othersArray<Expression | unknown>Optional additional values to check if previous values are null.

<b>Returns:</b>

FunctionExpression

A new Expression representing the coalesce operation.

Example

typescript
// Returns the value of the first non-null, non-absent field among 'preferredName', 'fullName',
// or the last argument if all previous fields are null.
field("preferredName").coalesce(field("fullName"), "Anonymous");

Expression.collectionId()

Creates an expression that returns the collection ID from a path.

<b>Signature:</b>

typescript
collectionId(): FunctionExpression;

<b>Returns:</b>

FunctionExpression

A new Expression representing the collectionId operation.

Example

typescript
// Get the collection ID from a path.
field("__path__").collectionId();

Expression.concat()

Creates an expression that concatenates expression results together.

<b>Signature:</b>

typescript
concat(second: Expression | unknown, ...others: Array<Expression | unknown>): FunctionExpression;

Parameters

ParameterTypeDescription
secondExpression | unknownThe additional expression or literal to concatenate.
othersArray<Expression | unknown>Optional additional expressions or literals to concatenate.

<b>Returns:</b>

FunctionExpression

A new Expression representing the concatenated value.

Example

typescript
// Combine the 'firstName', ' ', and 'lastName' fields into a single value.
field("firstName").concat(constant(" "), field("lastName"));

Expression.cosineDistance()

Calculates the cosine distance between two vectors.

<b>Signature:</b>

typescript
cosineDistance(vectorExpression: Expression): FunctionExpression;

Parameters

ParameterTypeDescription
vectorExpressionExpressionThe other vector (represented as an Expression) to compare against.

<b>Returns:</b>

FunctionExpression

A new Expression representing the cosine distance between the two vectors.

Example

typescript
// Calculate the cosine distance between the 'userVector' field and the 'itemVector' field
field("userVector").cosineDistance(field("itemVector"));

Expression.cosineDistance()

Calculates the Cosine distance between two vectors.

<b>Signature:</b>

typescript
cosineDistance(vector: VectorValue | number[]): FunctionExpression;

Parameters

ParameterTypeDescription
vectorVectorValue | number[]The other vector (as a VectorValue) to compare against.

<b>Returns:</b>

FunctionExpression

A new Expression representing the Cosine* distance between the two vectors.

Example

typescript
// Calculate the Cosine distance between the 'location' field and a target location
field("location").cosineDistance(new VectorValue([37.7749, -122.4194]));

Expression.count()

Creates an aggregation that counts the number of stage inputs with valid evaluations of the expression or field.

<b>Signature:</b>

typescript
count(): AggregateFunction;

<b>Returns:</b>

AggregateFunction

A new AggregateFunction representing the 'count' aggregation.

Example

typescript
// Count the total number of products
field("productId").count().as("totalProducts");

Expression.countDistinct()

Creates an aggregation that counts the number of distinct values of the expression or field.

<b>Signature:</b>

typescript
countDistinct(): AggregateFunction;

<b>Returns:</b>

AggregateFunction

A new AggregateFunction representing the 'count_distinct' aggregation.

Example

typescript
// Count the distinct number of products
field("productId").countDistinct().as("distinctProducts");

Expression.descending()

Creates an Ordering that sorts documents in descending order based on this expression.

<b>Signature:</b>

typescript
descending(): Ordering;

<b>Returns:</b>

Ordering

A new Ordering for descending sorting.

Example

typescript
// Sort documents by the 'createdAt' field in descending order
firestore.pipeline().collection("users")
  .sort(field("createdAt").descending());

Expression.divide()

Creates an expression that divides this expression by another expression.

<b>Signature:</b>

typescript
divide(divisor: Expression): FunctionExpression;

Parameters

ParameterTypeDescription
divisorExpressionThe expression to divide by.

<b>Returns:</b>

FunctionExpression

A new Expression representing the division operation.

Example

typescript
// Divide the 'total' field by the 'count' field
field("total").divide(field("count"));

Expression.divide()

Creates an expression that divides this expression by a constant value.

<b>Signature:</b>

typescript
divide(divisor: number): FunctionExpression;

Parameters

ParameterTypeDescription
divisornumberThe constant value to divide by.

<b>Returns:</b>

FunctionExpression

A new Expression representing the division operation.

Example

typescript
// Divide the 'value' field by 10
field("value").divide(10);

Expression.documentId()

Creates an expression that returns the document ID from a path.

<b>Signature:</b>

typescript
documentId(): FunctionExpression;

<b>Returns:</b>

FunctionExpression

A new Expression representing the documentId operation.

Example

typescript
// Get the document ID from a path.
field("__path__").documentId();

Expression.dotProduct()

Calculates the dot product between two vectors.

<b>Signature:</b>

typescript
dotProduct(vectorExpression: Expression): FunctionExpression;

Parameters

ParameterTypeDescription
vectorExpressionExpressionThe other vector (as an array of numbers) to calculate with.

<b>Returns:</b>

FunctionExpression

A new Expression representing the dot product between the two vectors.

Example

typescript
// Calculate the dot product between a feature vector and a target vector
field("features").dotProduct([0.5, 0.8, 0.2]);

Expression.dotProduct()

Calculates the dot product between two vectors.

<b>Signature:</b>

typescript
dotProduct(vector: VectorValue | number[]): FunctionExpression;

Parameters

ParameterTypeDescription
vectorVectorValue | number[]The other vector (as an array of numbers) to calculate with.

<b>Returns:</b>

FunctionExpression

A new Expression representing the dot product between the two vectors.

Example

typescript
// Calculate the dot product between a feature vector and a target vector
field("features").dotProduct(new VectorValue([0.5, 0.8, 0.2]));

Expression.endsWith()

Creates an expression that checks if a string ends with a given postfix.

<b>Signature:</b>

typescript
endsWith(suffix: string): BooleanExpression;

Parameters

ParameterTypeDescription
suffixstringThe postfix to check for.

<b>Returns:</b>

BooleanExpression

A new Expression representing the 'ends with' comparison.

Example

typescript
// Check if the 'filename' field ends with ".txt"
field("filename").endsWith(".txt");

Expression.endsWith()

Creates an expression that checks if a string ends with a given postfix (represented as an expression).

<b>Signature:</b>

typescript
endsWith(suffix: Expression): BooleanExpression;

Parameters

ParameterTypeDescription
suffixExpressionThe postfix expression to check for.

<b>Returns:</b>

BooleanExpression

A new Expression representing the 'ends with' comparison.

Example

typescript
// Check if the 'url' field ends with the value of the 'extension' field
field("url").endsWith(field("extension"));

Expression.equal()

Creates an expression that checks if this expression is equal to another expression.

<b>Signature:</b>

typescript
equal(expression: Expression): BooleanExpression;

Parameters

ParameterTypeDescription
expressionExpressionThe expression to compare for equality.

<b>Returns:</b>

BooleanExpression

A new Expression representing the equality comparison.

Example

typescript
// Check if the 'age' field is equal to 21
field("age").equal(21);

Expression.equal()

Creates an expression that checks if this expression is equal to a constant value.

<b>Signature:</b>

typescript
equal(value: unknown): BooleanExpression;

Parameters

ParameterTypeDescription
valueunknownThe constant value to compare for equality.

<b>Returns:</b>

BooleanExpression

A new Expression representing the equality comparison.

Example

typescript
// Check if the 'city' field is equal to "London"
field("city").equal("London");

Expression.equalAny()

Creates an expression that checks if this expression is equal to any of the provided values or expressions.

<b>Signature:</b>

typescript
equalAny(values: Array<Expression | unknown>): BooleanExpression;

Parameters

ParameterTypeDescription
valuesArray<Expression | unknown>The values or expressions to check against.

<b>Returns:</b>

BooleanExpression

A new Expression representing the 'IN' comparison.

Example

typescript
// Check if the 'category' field is either "Electronics" or value of field 'primaryType'
field("category").equalAny(["Electronics", field("primaryType")]);

Expression.equalAny()

Creates an expression that checks if this expression is equal to any of the provided values or expressions.

<b>Signature:</b>

typescript
equalAny(arrayExpression: Expression): BooleanExpression;

Parameters

ParameterTypeDescription
arrayExpressionExpressionAn expression that evaluates to an array of values to check against.

<b>Returns:</b>

BooleanExpression

A new Expression representing the 'IN' comparison.

Example

typescript
// Check if the 'category' field is either "Electronics" or value of field 'primaryType'
field("category").equalAny(array(["Electronics", field("primaryType")]));

Expression.euclideanDistance()

Calculates the Euclidean distance between two vectors.

<b>Signature:</b>

typescript
euclideanDistance(vectorExpression: Expression): FunctionExpression;

Parameters

ParameterTypeDescription
vectorExpressionExpressionThe other vector (as an array of numbers) to calculate with.

<b>Returns:</b>

FunctionExpression

A new Expression representing the Euclidean distance between the two vectors.

Example

typescript
// Calculate the Euclidean distance between the 'location' field and a target location
field("location").euclideanDistance([37.7749, -122.4194]);

Expression.euclideanDistance()

Calculates the Euclidean distance between two vectors.

<b>Signature:</b>

typescript
euclideanDistance(vector: VectorValue | number[]): FunctionExpression;

Parameters

ParameterTypeDescription
vectorVectorValue | number[]The other vector (as a VectorValue) to compare against.

<b>Returns:</b>

FunctionExpression

A new Expression representing the Euclidean distance between the two vectors.

Example

typescript
// Calculate the Euclidean distance between the 'location' field and a target location
field("location").euclideanDistance(new VectorValue([37.7749, -122.4194]));

Expression.exists()

Creates an expression that checks if a field exists in the document.

<b>Signature:</b>

typescript
exists(): BooleanExpression;

<b>Returns:</b>

BooleanExpression

A new Expression representing the 'exists' check.

Example

typescript
// Check if the document has a field named "phoneNumber"
field("phoneNumber").exists();

Expression.exp()

Creates an expression that computes e to the power of this expression.

<b>Signature:</b>

typescript
exp(): FunctionExpression;

<b>Returns:</b>

FunctionExpression

A new Expression representing the exp of the numeric value.

Example

typescript
// Compute e to the power of the 'value' field.
field("value").exp();

Expression.first()

Creates an aggregation that finds the first value of an expression across multiple stage inputs.

<b>Signature:</b>

typescript
first(): AggregateFunction;

<b>Returns:</b>

AggregateFunction

A new AggregateFunction representing the 'first' aggregation.

Example

typescript
// Find the first value of the 'rating' field
field("rating").first().as("firstRating");

Expression.floor()

Creates an expression that computes the floor of a numeric value.

<b>Signature:</b>

typescript
floor(): FunctionExpression;

<b>Returns:</b>

FunctionExpression

A new Expression representing the floor of the numeric value.

Example

typescript
// Compute the floor of the 'price' field.
field("price").floor();

Expression.getField()

Creates an expression that returns the value of a field from the document that results from the evaluation of this expression.

<b>Signature:</b>

typescript
getField(key: string | Expression): Expression;

Parameters

ParameterTypeDescription
keystring | ExpressionThe field to access in the document.

<b>Returns:</b>

Expression

A new Expression representing the value of the field in the document.

Example

typescript
// Get the value of the "city" field in the "address" document.
field("address").getField("city")

Expression.greaterThan()

Creates an expression that checks if this expression is greater than another expression.

<b>Signature:</b>

typescript
greaterThan(expression: Expression): BooleanExpression;

Parameters

ParameterTypeDescription
expressionExpressionThe expression to compare for greater than.

<b>Returns:</b>

BooleanExpression

A new Expression representing the greater than comparison.

Example

typescript
// Check if the 'age' field is greater than the 'limit' field
field("age").greaterThan(field("limit"));

Expression.greaterThan()

Creates an expression that checks if this expression is greater than a constant value.

<b>Signature:</b>

typescript
greaterThan(value: unknown): BooleanExpression;

Parameters

ParameterTypeDescription
valueunknownThe constant value to compare for greater than.

<b>Returns:</b>

BooleanExpression

A new Expression representing the greater than comparison.

Example

typescript
// Check if the 'price' field is greater than 100
field("price").greaterThan(100);

Expression.greaterThanOrEqual()

Creates an expression that checks if this expression is greater than or equal to another expression.

<b>Signature:</b>

typescript
greaterThanOrEqual(expression: Expression): BooleanExpression;

Parameters

ParameterTypeDescription
expressionExpressionThe expression to compare for greater than or equal to.

<b>Returns:</b>

BooleanExpression

A new Expression representing the greater than or equal to comparison.

Example

typescript
// Check if the 'quantity' field is greater than or equal to field 'requirement' plus 1
field("quantity").greaterThanOrEqual(field('requirement').add(1));

Expression.greaterThanOrEqual()

Creates an expression that checks if this expression is greater than or equal to a constant value.

<b>Signature:</b>

typescript
greaterThanOrEqual(value: unknown): BooleanExpression;

Parameters

ParameterTypeDescription
valueunknownThe constant value to compare for greater than or equal to.

<b>Returns:</b>

BooleanExpression

A new Expression representing the greater than or equal to comparison.

Example

typescript
// Check if the 'score' field is greater than or equal to 80
field("score").greaterThanOrEqual(80);

Expression.ifAbsent()

Creates an expression that returns the elseValue argument if this expression results in an absent value, else return the result of this expression evaluation.

<b>Signature:</b>

typescript
ifAbsent(elseValue: unknown): Expression;

Parameters

ParameterTypeDescription
elseValueunknownThe value that will be returned if this Expression evaluates to an absent value.

<b>Returns:</b>

Expression

A new [Expression] representing the ifAbsent operation.

Example

typescript
// Returns the value of the optional field 'optional_field', or returns 'default_value'
// if the field is absent.
field("optional_field").ifAbsent("default_value")

Expression.ifAbsent()

Creates an expression that returns the elseValue argument if this expression results in an absent value, else return the result of this expression evaluation.

<b>Signature:</b>

typescript
ifAbsent(elseExpression: unknown): Expression;

Parameters

ParameterTypeDescription
elseExpressionunknownThe Expression that will be evaluated if this Expression evaluates to an absent value.

<b>Returns:</b>

Expression

A new [Expression] representing the ifAbsent operation.

Example

typescript
// Returns the value of the optional field 'optional_field', or if that is
// absent, then returns the value of the field `default_field`.
field("optional_field").ifAbsent(field('default_field'))

Expression.ifError()

Creates an expression that returns the result of the catchExpr argument if there is an error, else return the result of this expression.

<b>Signature:</b>

typescript
ifError(catchExpr: Expression): FunctionExpression;

Parameters

ParameterTypeDescription
catchExprExpressionThe catch expression that will be evaluated and returned if this expression produces an error.

<b>Returns:</b>

FunctionExpression

A new Expression representing the 'ifError' operation.

Example

typescript
// Returns the first item in the title field arrays, or returns
// the entire title field if the array is empty or the field is another type.
field("title").arrayGet(0).ifError(field("title"));

Expression.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
// Returns the first item in the title field arrays, or returns
// "Default Title"
field("title").arrayGet(0).ifError("Default Title");

Expression.ifNull()

Creates an expression that returns the elseValue argument if this expression evaluates to null, else return the result of this expression evaluation.

This function provides a fallback for both absent and explicit null values. In contrast, ifAbsent() only triggers for missing fields.

<b>Signature:</b>

typescript
ifNull(elseExpression: Expression): FunctionExpression;

Parameters

ParameterTypeDescription
elseExpressionExpressionThe Expression that will be evaluated if this Expression evaluates to null.

<b>Returns:</b>

FunctionExpression

A new Expression representing the ifNull operation.

Example

typescript
// Returns the user's preferred name, or if that is null, returns their full name.
field("preferredName").ifNull(field("fullName"))

Expression.ifNull()

Creates an expression that returns the elseValue argument if this expression evaluates to null, else return the result of this expression evaluation.

This function provides a fallback for both absent and explicit null values. In contrast, ifAbsent() only triggers for missing fields.

<b>Signature:</b>

typescript
ifNull(elseValue: unknown): FunctionExpression;

Parameters

ParameterTypeDescription
elseValueunknownThe value that will be returned if this Expression evaluates to null.

<b>Returns:</b>

FunctionExpression

A new Expression representing the ifNull operation.

Example

typescript
// Returns the user's display name, or returns "Anonymous" if the field is null.
field("displayName").ifNull("Anonymous")

Expression.isAbsent()

Creates an expression that returns true if the result of this expression is absent. Otherwise, returns false even if the value is null<!-- -->.

<b>Signature:</b>

typescript
isAbsent(): BooleanExpression;

<b>Returns:</b>

BooleanExpression

A new BooleanExpression representing the 'isAbsent' check.

Example

typescript
// Check if the field `value` is absent.
field("value").isAbsent();

Expression.isError()

Creates an expression that checks if a given expression produces an error.

<b>Signature:</b>

typescript
isError(): BooleanExpression;

<b>Returns:</b>

BooleanExpression

A new BooleanExpression representing the 'isError' check.

Example

typescript
// Check if the result of a calculation is an error
field("title").arrayContains(1).isError();

Expression.isType()

Creates an expression that checks if the result of this expression is of the given type.

Null or undefined fields evaluate to skip/error. Use ifAbsent() / isAbsent() to evaluate missing data. Supported values for type are: 'null'<!-- -->, 'array'<!-- -->, 'boolean'<!-- -->, 'bytes'<!-- -->, 'timestamp'<!-- -->, 'geo_point'<!-- -->, 'number'<!-- -->, 'int32'<!-- -->, 'int64'<!-- -->, 'float64'<!-- -->, 'decimal128'<!-- -->, 'map'<!-- -->, 'reference'<!-- -->, 'string'<!-- -->, 'vector'<!-- -->, 'max_key'<!-- -->, 'min_key'<!-- -->, 'object_id'<!-- -->, 'regex'<!-- -->, 'request_timestamp'<!-- -->.

<b>Signature:</b>

typescript
isType(type: string): BooleanExpression;

Parameters

ParameterTypeDescription
typestringThe type to check for.

<b>Returns:</b>

BooleanExpression

A new BooleanExpression that evaluates to true if the expression's result is of the given type, false otherwise.

Example

typescript
// Check if the 'price' field is specifically an integer (not just 'number')
field('price').isType('int64');

Expression.join()

Creates an expression that joins the elements of an array into a string.

<b>Signature:</b>

typescript
join(delimiterExpression: Expression): Expression;

Parameters

ParameterTypeDescription
delimiterExpressionExpressionThe expression that evaluates to the delimiter string.

<b>Returns:</b>

Expression

A new Expression representing the join operation.

Example

typescript
// Join the elements of the 'tags' field with the delimiter from the 'separator' field.
field("tags").join(field("separator"))

Expression.join()

Creates an expression that joins the elements of an array field into a string.

<b>Signature:</b>

typescript
join(delimiter: string): Expression;

Parameters

ParameterTypeDescription
delimiterstringThe string to use as a delimiter.

<b>Returns:</b>

Expression

A new Expression representing the join operation.

Example

typescript
// Join the elements of the 'tags' field with a comma and space.
field("tags").join(", ")

Expression.last()

Creates an aggregation that finds the last value of an expression across multiple stage inputs.

<b>Signature:</b>

typescript
last(): AggregateFunction;

<b>Returns:</b>

AggregateFunction

A new AggregateFunction representing the 'last' aggregation.

Example

typescript
// Find the last value of the 'rating' field
field("rating").last().as("lastRating");

Expression.length()

Creates an expression that calculates the length of a string, array, map, vector, or bytes.

<b>Signature:</b>

typescript
length(): FunctionExpression;

<b>Returns:</b>

FunctionExpression

A new Expression representing the length of the string, array, map, vector, or bytes.

Example

typescript
// Get the length of the 'name' field.
field("name").length();

// Get the number of items in the 'cart' array.
field("cart").length();

Expression.lessThan()

Creates an expression that checks if this expression is less than another expression.

<b>Signature:</b>

typescript
lessThan(experession: Expression): BooleanExpression;

Parameters

ParameterTypeDescription
experessionExpressionThe expression to compare for less than.

<b>Returns:</b>

BooleanExpression

A new Expression representing the less than comparison.

Example

typescript
// Check if the 'age' field is less than 'limit'
field("age").lessThan(field('limit'));

Expression.lessThan()

Creates an expression that checks if this expression is less than a constant value.

<b>Signature:</b>

typescript
lessThan(value: unknown): BooleanExpression;

Parameters

ParameterTypeDescription
valueunknownThe constant value to compare for less than.

<b>Returns:</b>

BooleanExpression

A new Expression representing the less than comparison.

Example

typescript
// Check if the 'price' field is less than 50
field("price").lessThan(50);

Expression.lessThanOrEqual()

Creates an expression that checks if this expression is less than or equal to another expression.

<b>Signature:</b>

typescript
lessThanOrEqual(expression: Expression): BooleanExpression;

Parameters

ParameterTypeDescription
expressionExpressionThe expression to compare for less than or equal to.

<b>Returns:</b>

BooleanExpression

A new Expression representing the less than or equal to comparison.

Example

typescript
// Check if the 'quantity' field is less than or equal to 20
field("quantity").lessThan(constant(20));

Expression.lessThanOrEqual()

Creates an expression that checks if this expression is less than or equal to a constant value.

<b>Signature:</b>

typescript
lessThanOrEqual(value: unknown): BooleanExpression;

Parameters

ParameterTypeDescription
valueunknownThe constant value to compare for less than or equal to.

<b>Returns:</b>

BooleanExpression

A new Expression representing the less than or equal to comparison.

Example

typescript
// Check if the 'score' field is less than or equal to 70
field("score").lessThan(70);

Expression.like()

Creates an expression that performs a case-sensitive string comparison.

<b>Signature:</b>

typescript
like(pattern: string): BooleanExpression;

Parameters

ParameterTypeDescription
patternstringThe pattern to search for. You can use "%" as a wildcard character.

<b>Returns:</b>

BooleanExpression

A new Expression representing the 'like' comparison.

Example

typescript
// Check if the 'title' field contains the word "guide" (case-sensitive)
field("title").like("%guide%");

Expression.like()

Creates an expression that performs a case-sensitive string comparison.

<b>Signature:</b>

typescript
like(pattern: Expression): BooleanExpression;

Parameters

ParameterTypeDescription
patternExpressionThe pattern to search for. You can use "%" as a wildcard character.

<b>Returns:</b>

BooleanExpression

A new Expression representing the 'like' comparison.

Example

typescript
// Check if the 'title' field contains the word "guide" (case-sensitive)
field("title").like("%guide%");

Expression.ln()

Creates an expression that computes the natural logarithm of a numeric value.

<b>Signature:</b>

typescript
ln(): FunctionExpression;

<b>Returns:</b>

FunctionExpression

A new Expression representing the natural logarithm of the numeric value.

Example

typescript
// Compute the natural logarithm of the 'value' field.
field("value").ln();

Expression.log10()

Creates an expression that computes the base-10 logarithm of a numeric value.

<b>Signature:</b>

typescript
log10(): FunctionExpression;

<b>Returns:</b>

FunctionExpression

A new Expression representing the base-10 logarithm of the numeric value.

Example

typescript
// Compute the base-10 logarithm of the 'value' field.
field("value").log10();

Expression.logicalMaximum()

Creates an expression that returns the larger value between this expression and another expression, based on Firestore's value type ordering.

<b>Signature:</b>

typescript
logicalMaximum(second: Expression | unknown, ...others: Array<Expression | unknown>): FunctionExpression;

Parameters

ParameterTypeDescription
secondExpression | unknownThe second expression or literal to compare with.
othersArray<Expression | unknown>Optional additional expressions or literals to compare with.

<b>Returns:</b>

FunctionExpression

A new Expression representing the logical maximum operation.

Example

typescript
// Returns the larger value between the 'timestamp' field and the current timestamp.
field("timestamp").logicalMaximum(currentTimestamp());

Expression.logicalMinimum()

Creates an expression that returns the smaller value between this expression and another expression, based on Firestore's value type ordering.

<b>Signature:</b>

typescript
logicalMinimum(second: Expression | unknown, ...others: Array<Expression | unknown>): FunctionExpression;

Parameters

ParameterTypeDescription
secondExpression | unknownThe second expression or literal to compare with.
othersArray<Expression | unknown>Optional additional expressions or literals to compare with.

<b>Returns:</b>

FunctionExpression

A new Expression representing the logical minimum operation.

Example

typescript
// Returns the smaller value between the 'timestamp' field and the current timestamp.
field("timestamp").logicalMinimum(currentTimestamp());

Expression.ltrim()

Trims whitespace or a specified set of characters/bytes from the beginning of a string or byte array.

<b>Signature:</b>

typescript
ltrim(valueToTrim?: string | Expression | Bytes): FunctionExpression;

Parameters

ParameterTypeDescription
valueToTrimstring | Expression | BytesOptional. A string or byte array containing the characters/bytes to trim. If not specified, whitespace will be trimmed.

<b>Returns:</b>

FunctionExpression

A new Expression representing the trimmed string.

Example

typescript
// Trim whitespace from the beginning of the 'userInput' field
field("userInput").ltrim();

// Trim quotes from the beginning of the 'userInput' field
field("userInput").ltrim('"');

Expression.mapEntries()

Creates an expression that returns the entries of a map as an array of maps, where each map contains a "k" property for the key and a "v" property for the value. For example: [{ k: "key1", v: "value1" }, ...]<!-- -->.

<b>Signature:</b>

typescript
mapEntries(): FunctionExpression;

<b>Returns:</b>

FunctionExpression

A new Expression representing the entries of the map.

Example

typescript
// Get the entries of the 'address' map
field("address").mapEntries();

Expression.mapGet()

Accesses a value from a map (object) field using the provided key.

<b>Signature:</b>

typescript
mapGet(subfield: string): FunctionExpression;

Parameters

ParameterTypeDescription
subfieldstringThe key to access in the map.

<b>Returns:</b>

FunctionExpression

A new Expression representing the value associated with the given key in the map.

Example

typescript
// Get the 'city' value from the 'address' map field
field("address").mapGet("city");

Expression.mapKeys()

Creates an expression that returns the keys of a map.

While the backend generally preserves insertion order, relying on the order of the output array is not guaranteed and should be avoided.

<b>Signature:</b>

typescript
mapKeys(): FunctionExpression;

<b>Returns:</b>

FunctionExpression

A new Expression representing the keys of the map.

Example

typescript
// Get the keys of the 'address' map
field("address").mapKeys();

Expression.mapMerge()

Creates an expression that merges multiple map values.

<b>Signature:</b>

typescript
mapMerge(secondMap: Record<string, unknown> | Expression, ...otherMaps: Array<Record<string, unknown> | Expression>): FunctionExpression;

Parameters

ParameterTypeDescription
secondMapRecord<string, unknown> | ExpressionA required second map to merge. Represented as a literal or an expression that returns a map.
otherMapsArray<Record<string, unknown> | Expression<!-- -->>Optional additional maps to merge. Each map is represented as a literal or an expression that returns a map.

<b>Returns:</b>

FunctionExpression

A new Expression representing the 'mapMerge' operation.

Example

// Merges the map in the settings field with, a map literal, and a map in
// that is conditionally returned by another expression
field('settings').mapMerge({ enabled: true }, conditional(field('isAdmin'), { admin: true}, {})

Expression.mapRemove()

Creates an expression that removes a key from the map produced by evaluating this expression.

<b>Signature:</b>

typescript
mapRemove(key: string): FunctionExpression;

Parameters

ParameterTypeDescription
keystringThe name of the key to remove from the input map.

<b>Returns:</b>

FunctionExpression

A new Expression representing the 'mapRemove' operation.

Example

// Removes the key 'baz' from the input map.
map({foo: 'bar', baz: true}).mapRemove('baz');

Expression.mapRemove()

Creates an expression that removes a key from the map produced by evaluating this expression.

<b>Signature:</b>

typescript
mapRemove(keyExpr: Expression): FunctionExpression;

Parameters

ParameterTypeDescription
keyExprExpressionAn expression that produces the name of the key to remove from the input map.

<b>Returns:</b>

FunctionExpression

A new Expression representing the 'mapRemove' operation.

Example

// Removes the key 'baz' from the input map.
map({foo: 'bar', baz: true}).mapRemove(constant('baz'));
@example

Expression.mapSet()

Creates an expression that returns a new map with the specified entries added or updated.

Note that mapSet only performs shallow updates to the map. Setting a value to null will retain the key with a null value. To remove a key entirely, use mapRemove<!-- -->.

<b>Signature:</b>

typescript
mapSet(key: string | Expression, value: unknown, ...moreKeyValues: unknown[]): FunctionExpression;

Parameters

ParameterTypeDescription
keystring | ExpressionThe key to set. Must be a string or a constant string expression.
valueunknownThe value to set.
moreKeyValuesunknown[]Additional key-value pairs to set.

<b>Returns:</b>

FunctionExpression

A new Expression representing the map with the entries set.

Example

typescript
// Set the 'city' to "San Francisco" in the 'address' map
field("address").mapSet("city", "San Francisco");

Expression.mapValues()

Creates an expression that returns the values of a map.

While the backend generally preserves insertion order, relying on the order of the output array is not guaranteed and should be avoided.

<b>Signature:</b>

typescript
mapValues(): FunctionExpression;

<b>Returns:</b>

FunctionExpression

A new Expression representing the values of the map.

Example

typescript
// Get the values of the 'address' map
field("address").mapValues();

Expression.maximum()

Creates an aggregation that finds the maximum value of a field across multiple stage inputs.

<b>Signature:</b>

typescript
maximum(): AggregateFunction;

<b>Returns:</b>

AggregateFunction

A new AggregateFunction representing the 'maximum' aggregation.

Example

typescript
// Find the highest score in a leaderboard
field("score").maximum().as("highestScore");

Expression.minimum()

Creates an aggregation that finds the minimum value of a field across multiple stage inputs.

<b>Signature:</b>

typescript
minimum(): AggregateFunction;

<b>Returns:</b>

AggregateFunction

A new AggregateFunction representing the 'minimum' aggregation.

Example

typescript
// Find the lowest price of all products
field("price").minimum().as("lowestPrice");

Expression.mod()

Creates an expression that calculates the modulo (remainder) of dividing this expression by another expression.

<b>Signature:</b>

typescript
mod(expression: Expression): FunctionExpression;

Parameters

ParameterTypeDescription
expressionExpressionThe expression to divide by.

<b>Returns:</b>

FunctionExpression

A new Expression representing the modulo operation.

Example

typescript
// Calculate the remainder of dividing the 'value' field by the 'divisor' field
field("value").mod(field("divisor"));

Expression.mod()

Creates an expression that calculates the modulo (remainder) of dividing this expression by a constant value.

<b>Signature:</b>

typescript
mod(value: number): FunctionExpression;

Parameters

ParameterTypeDescription
valuenumberThe constant value to divide by.

<b>Returns:</b>

FunctionExpression

A new Expression representing the modulo operation.

Example

typescript
// Calculate the remainder of dividing the 'value' field by 10
field("value").mod(10);

Expression.multiply()

Creates an expression that multiplies this expression by another expression.

<b>Signature:</b>

typescript
multiply(second: Expression | number): FunctionExpression;

Parameters

ParameterTypeDescription
secondExpression | numberThe second expression or literal to multiply by.

<b>Returns:</b>

FunctionExpression

A new Expression representing the multiplication operation.

Example

typescript
// Multiply the 'quantity' field by the 'price' field
field("quantity").multiply(field("price"));

Expression.notEqual()

Creates an expression that checks if this expression is not equal to another expression.

<b>Signature:</b>

typescript
notEqual(expression: Expression): BooleanExpression;

Parameters

ParameterTypeDescription
expressionExpressionThe expression to compare for inequality.

<b>Returns:</b>

BooleanExpression

A new Expression representing the inequality comparison.

Example

typescript
// Check if the 'status' field is not equal to "completed"
field("status").notEqual("completed");

Expression.notEqual()

Creates an expression that checks if this expression is not equal to a constant value.

<b>Signature:</b>

typescript
notEqual(value: unknown): BooleanExpression;

Parameters

ParameterTypeDescription
valueunknownThe constant value to compare for inequality.

<b>Returns:</b>

BooleanExpression

A new Expression representing the inequality comparison.

Example

typescript
// Check if the 'country' field is not equal to "USA"
field("country").notEqual("USA");

Expression.notEqualAny()

Creates an expression that checks if this expression is not equal to any of the provided values or expressions.

<b>Signature:</b>

typescript
notEqualAny(values: Array<Expression | unknown>): BooleanExpression;

Parameters

ParameterTypeDescription
valuesArray<Expression | unknown>The values or expressions to check against.

<b>Returns:</b>

BooleanExpression

A new Expression representing the 'notEqualAny' comparison.

Example

typescript
// Check if the 'status' field is neither "pending" nor the value of 'rejectedStatus'
field("status").notEqualAny(["pending", field("rejectedStatus")]);

Expression.notEqualAny()

Creates an expression that checks if this expression is not equal to any of the values in the evaluated expression.

<b>Signature:</b>

typescript
notEqualAny(arrayExpression: Expression): BooleanExpression;

Parameters

ParameterTypeDescription
arrayExpressionExpressionThe values or expressions to check against.

<b>Returns:</b>

BooleanExpression

A new Expression representing the 'notEqualAny' comparison.

Example

typescript
// Check if the 'status' field is not equal to any value in the field 'rejectedStatuses'
field("status").notEqualAny(field('rejectedStatuses'));

Expression.parent()

Creates an expression that returns the parent document reference of a document reference.

<b>Signature:</b>

typescript
parent(): FunctionExpression;

<b>Returns:</b>

FunctionExpression

A new Expression representing the parent operation.

Example

typescript
// Get the parent document reference of a document reference.
field("__path__").parent();

Expression.pow()

Creates an expression that returns the value of this expression raised to the power of another expression.

<b>Signature:</b>

typescript
pow(exponent: Expression): FunctionExpression;

Parameters

ParameterTypeDescription
exponentExpressionThe expression to raise this expression to the power of.

<b>Returns:</b>

FunctionExpression

A new Expression representing the power operation.

Example

typescript
// Raise the value of the 'base' field to the power of the 'exponent' field.
field("base").pow(field("exponent"));

Expression.pow()

Creates an expression that returns the value of this expression raised to the power of a constant value.

<b>Signature:</b>

typescript
pow(exponent: number): FunctionExpression;

Parameters

ParameterTypeDescription
exponentnumberThe constant value to raise this expression to the power of.

<b>Returns:</b>

FunctionExpression

A new Expression representing the power operation.

Example

typescript
// Raise the value of the 'base' field to the power of 2.
field("base").pow(2);

Expression.regexContains()

Creates an expression that checks if a string contains a specified regular expression as a substring.

<b>Signature:</b>

typescript
regexContains(pattern: string): BooleanExpression;

Parameters

ParameterTypeDescription
patternstringThe regular expression to use for the search.

<b>Returns:</b>

BooleanExpression

A new Expression representing the 'contains' comparison.

Example

typescript
// Check if the 'description' field contains "example" (case-insensitive)
field("description").regexContains("(?i)example");

Expression.regexContains()

Creates an expression that checks if a string contains a specified regular expression as a substring.

<b>Signature:</b>

typescript
regexContains(pattern: Expression): BooleanExpression;

Parameters

ParameterTypeDescription
patternExpressionThe regular expression to use for the search.

<b>Returns:</b>

BooleanExpression

A new Expression representing the 'contains' comparison.

Example

typescript
// Check if the 'description' field contains the regular expression stored in field 'regex'
field("description").regexContains(field("regex"));

Expression.regexFind()

Creates an expression that returns the first substring of a string expression that matches a specified regular expression.

This expression uses the RE2 regular expression syntax.

<b>Signature:</b>

typescript
regexFind(pattern: string): FunctionExpression;

Parameters

ParameterTypeDescription
patternstringThe regular expression to search for.

<b>Returns:</b>

FunctionExpression

A new Expression representing the regular expression find function.

Example

typescript
// Extract the domain from an email address
field("email").regexFind("@.+")

Expression.regexFind()

Creates an expression that returns the first substring of a string expression that matches a specified regular expression.

This expression uses the RE2 regular expression syntax.

<b>Signature:</b>

typescript
regexFind(pattern: Expression): FunctionExpression;

Parameters

ParameterTypeDescription
patternExpressionThe regular expression to search for.

<b>Returns:</b>

FunctionExpression

A new Expression representing the regular expression find function.

Example

typescript
// Extract the domain from an email address
field("email").regexFind(field("domain"))

Expression.regexFindAll()

Creates an expression that evaluates to a list of all substrings in this string expression that match a specified regular expression.

This expression uses the RE2 regular expression syntax.

<b>Signature:</b>

typescript
regexFindAll(pattern: string): FunctionExpression;

Parameters

ParameterTypeDescription
patternstringThe regular expression to search for.

<b>Returns:</b>

FunctionExpression

A new Expression that evaluates to an array of matched substrings.

Example

typescript
// Extract all hashtags from a post content field
field("content").regexFindAll("#[A-Za-z0-9_]+")

Expression.regexFindAll()

Creates an expression that evaluates to a list of all substrings in this string expression that match a specified regular expression.

This expression uses the RE2 regular expression syntax.

<b>Signature:</b>

typescript
regexFindAll(pattern: Expression): FunctionExpression;

Parameters

ParameterTypeDescription
patternExpressionThe regular expression to search for.

<b>Returns:</b>

FunctionExpression

A new Expression that evaluates to an array of matched substrings.

Example

typescript
// Extract all names from a post content field
field("content").regexFindAll(field("names"))

Expression.regexMatch()

Creates an expression that checks if a string matches a specified regular expression.

<b>Signature:</b>

typescript
regexMatch(pattern: string): BooleanExpression;

Parameters

ParameterTypeDescription
patternstringThe regular expression to use for the match.

<b>Returns:</b>

BooleanExpression

A new Expression representing the regular expression match.

Example

typescript
// Check if the 'email' field matches a valid email pattern
field("email").regexMatch("[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\\.[A-Za-z]{2,}");

Expression.regexMatch()

Creates an expression that checks if a string matches a specified regular expression.

<b>Signature:</b>

typescript
regexMatch(pattern: Expression): BooleanExpression;

Parameters

ParameterTypeDescription
patternExpressionThe regular expression to use for the match.

<b>Returns:</b>

BooleanExpression

A new Expression representing the regular expression match.

Example

typescript
// Check if the 'email' field matches a regular expression stored in field 'regex'
field("email").regexMatch(field("regex"));

Expression.reverse()

Creates an expression that reverses this string expression.

<b>Signature:</b>

typescript
reverse(): FunctionExpression;

<b>Returns:</b>

FunctionExpression

A new Expression representing the reversed string.

Example

typescript
// Reverse the value of the 'myString' field.
field("myString").reverse();

Expression.round()

Creates an expression that rounds a numeric value to the nearest whole number.

<b>Signature:</b>

typescript
round(): FunctionExpression;

<b>Returns:</b>

FunctionExpression

A new Expression representing the rounded value.

Example

typescript
// Round the value of the 'price' field.
field("price").round();

Expression.round()

Creates an expression that rounds a numeric value to the specified number of decimal places.

<b>Signature:</b>

typescript
round(decimalPlaces: number): FunctionExpression;

Parameters

ParameterTypeDescription
decimalPlacesnumberA constant specifying the rounding precision in decimal places.

<b>Returns:</b>

FunctionExpression

A new Expression representing the rounded value.

Example

typescript
// Round the value of the 'price' field to two decimal places.
field("price").round(2);

Expression.round()

Creates an expression that rounds a numeric value to the specified number of decimal places.

<b>Signature:</b>

typescript
round(decimalPlaces: Expression): FunctionExpression;

Parameters

ParameterTypeDescription
decimalPlacesExpressionAn expression specifying the rounding precision in decimal places.

<b>Returns:</b>

FunctionExpression

A new Expression representing the rounded value.

Example

typescript
// Round the value of the 'price' field to two decimal places.
field("price").round(constant(2));

Expression.rtrim()

Trims whitespace or a specified set of characters/bytes from the end of a string or byte array.

<b>Signature:</b>

typescript
rtrim(valueToTrim?: string | Expression | Bytes): FunctionExpression;

Parameters

ParameterTypeDescription
valueToTrimstring | Expression | BytesOptional. A string or byte array containing the characters/bytes to trim. If not specified, whitespace will be trimmed.

<b>Returns:</b>

FunctionExpression

A new Expression representing the trimmed string or byte array.

Example

typescript
// Trim whitespace from the end of the 'userInput' field
field("userInput").rtrim();

// Trim quotes from the end of the 'userInput' field
field("userInput").rtrim('"');

Expression.split()

Creates an expression that splits the result of this expression into an array of substrings based on the provided delimiter.

<b>Signature:</b>

typescript
split(delimiter: string): FunctionExpression;

Parameters

ParameterTypeDescription
delimiterstring

<b>Returns:</b>

FunctionExpression

A new Expression representing the split function.

Example

typescript
// Split the 'scoresCsv' field on delimiter ','
field('scoresCsv').split(',')

Expression.split()

Creates an expression that splits the result of this expression into an array of substrings based on the provided delimiter.

<b>Signature:</b>

typescript
split(delimiter: Expression): FunctionExpression;

Parameters

ParameterTypeDescription
delimiterExpression

<b>Returns:</b>

FunctionExpression

A new Expression representing the split function.

Example

typescript
// Split the 'scores' field on delimiter ',' or ':' depending on the stored format
field('scores').split(conditional(field('format').equal('csv'), constant(','), constant(':')))

Expression.sqrt()

Creates an expression that computes the square root of a numeric value.

<b>Signature:</b>

typescript
sqrt(): FunctionExpression;

<b>Returns:</b>

FunctionExpression

A new Expression representing the square root of the numeric value.

Example

typescript
// Compute the square root of the 'value' field.
field("value").sqrt();

Expression.startsWith()

Creates an expression that checks if a string starts with a given prefix.

<b>Signature:</b>

typescript
startsWith(prefix: string): BooleanExpression;

Parameters

ParameterTypeDescription
prefixstringThe prefix to check for.

<b>Returns:</b>

BooleanExpression

A new Expression representing the 'starts with' comparison.

Example

typescript
// Check if the 'name' field starts with "Mr."
field("name").startsWith("Mr.");

Expression.startsWith()

Creates an expression that checks if a string starts with a given prefix (represented as an expression).

<b>Signature:</b>

typescript
startsWith(prefix: Expression): BooleanExpression;

Parameters

ParameterTypeDescription
prefixExpressionThe prefix expression to check for.

<b>Returns:</b>

BooleanExpression

A new Expression representing the 'starts with' comparison.

Example

typescript
// Check if the 'fullName' field starts with the value of the 'firstName' field
field("fullName").startsWith(field("firstName"));

Expression.stringConcat()

Creates an expression that concatenates string expressions together.

<b>Signature:</b>

typescript
stringConcat(secondString: Expression | string, ...otherStrings: Array<Expression | string>): FunctionExpression;

Parameters

ParameterTypeDescription
secondStringExpression | stringThe additional expression or string literal to concatenate.
otherStringsArray<Expression | string>Optional additional expressions or string literals to concatenate.

<b>Returns:</b>

FunctionExpression

A new Expression representing the concatenated string.

Example

typescript
// Combine the 'firstName', " ", and 'lastName' fields into a single string
field("firstName").stringConcat(constant(" "), field("lastName"));

Expression.stringContains()

Creates an expression that checks if a string contains a specified substring.

<b>Signature:</b>

typescript
stringContains(substring: string): BooleanExpression;

Parameters

ParameterTypeDescription
substringstringThe substring to search for.

<b>Returns:</b>

BooleanExpression

A new Expression representing the 'contains' comparison.

Example

typescript
// Check if the 'description' field contains "example".
field("description").stringContains("example");

Expression.stringContains()

Creates an expression that checks if a string contains the string represented by another expression.

<b>Signature:</b>

typescript
stringContains(expr: Expression): BooleanExpression;

Parameters

ParameterTypeDescription
exprExpressionThe expression representing the substring to search for.

<b>Returns:</b>

BooleanExpression

A new Expression representing the 'contains' comparison.

Example

typescript
// Check if the 'description' field contains the value of the 'keyword' field.
field("description").stringContains(field("keyword"));

Expression.stringIndexOf()

Creates an expression that finds the index of the first occurrence of a substring or byte sequence.

<b>Signature:</b>

typescript
stringIndexOf(search: string | Expression | Bytes): FunctionExpression;

Parameters

ParameterTypeDescription
searchstring | Expression | BytesThe substring or byte sequence to search for.

<b>Returns:</b>

FunctionExpression

A new Expression representing the index of the first occurrence.

Example

typescript
// Find the index of "foo" in the 'text' field
field("text").stringIndexOf("foo");

Expression.stringRepeat()

Creates an expression that repeats a string or byte array a specified number of times.

<b>Signature:</b>

typescript
stringRepeat(repetitions: number | Expression): FunctionExpression;

Parameters

ParameterTypeDescription
repetitionsnumber | ExpressionThe number of times to repeat the string or byte array.

<b>Returns:</b>

FunctionExpression

A new Expression representing the repeated string or byte array.

Example

typescript
// Repeat the 'label' field 3 times
field("label").stringRepeat(3);

Expression.stringReplaceAll()

Creates an expression that replaces all occurrences of a substring or byte sequence with a replacement.

<b>Signature:</b>

typescript
stringReplaceAll(find: string | Expression | Bytes, replacement: string | Expression | Bytes): FunctionExpression;

Parameters

ParameterTypeDescription
findstring | Expression | BytesThe substring or byte sequence to search for.
replacementstring | Expression | BytesThe replacement string or byte sequence.

<b>Returns:</b>

FunctionExpression

A new Expression representing the string or byte array with replacements.

Example

typescript
// Replace all occurrences of "foo" with "bar" in the 'text' field
field("text").stringReplaceAll("foo", "bar");

Expression.stringReplaceOne()

Creates an expression that replaces the first occurrence of a substring or byte sequence with a replacement.

<b>Signature:</b>

typescript
stringReplaceOne(find: string | Expression | Bytes, replacement: string | Expression | Bytes): FunctionExpression;

Parameters

ParameterTypeDescription
findstring | Expression | BytesThe substring or byte sequence to search for.
replacementstring | Expression | BytesThe replacement string or byte sequence.

<b>Returns:</b>

FunctionExpression

A new Expression representing the string or byte array with the replacement.

Example

typescript
// Replace the first occurrence of "foo" with "bar" in the 'text' field
field("text").stringReplaceOne("foo", "bar");

Expression.stringReverse()

Creates an expression that reverses a string.

<b>Signature:</b>

typescript
stringReverse(): FunctionExpression;

<b>Returns:</b>

FunctionExpression

A new Expression representing the reversed string.

Example

typescript
// Reverse the value of the 'myString' field.
field("myString").stringReverse();

Expression.substring()

Creates an expression that returns a substring of the results of this expression.

<b>Signature:</b>

typescript
substring(position: number, length?: number): FunctionExpression;

Parameters

ParameterTypeDescription
positionnumberIndex of the first character of the substring.
lengthnumberLength of the substring. If not provided, the substring will end at the end of the input.

<b>Returns:</b>

FunctionExpression

Expression.substring()

Creates an expression that returns a substring of the results of this expression.

<b>Signature:</b>

typescript
substring(position: Expression, length?: Expression): FunctionExpression;

Parameters

ParameterTypeDescription
positionExpressionAn expression returning the index of the first character of the substring.
lengthExpressionAn expression returning the length of the substring. If not provided the substring will end at the end of the input.

<b>Returns:</b>

FunctionExpression

Expression.subtract()

Creates an expression that subtracts another expression from this expression.

<b>Signature:</b>

typescript
subtract(subtrahend: Expression): FunctionExpression;

Parameters

ParameterTypeDescription
subtrahendExpressionThe expression to subtract from this expression.

<b>Returns:</b>

FunctionExpression

A new Expression representing the subtraction operation.

Example

typescript
// Subtract the 'discount' field from the 'price' field
field("price").subtract(field("discount"));

Expression.subtract()

Creates an expression that subtracts a constant value from this expression.

<b>Signature:</b>

typescript
subtract(subtrahend: number): FunctionExpression;

Parameters

ParameterTypeDescription
subtrahendnumberThe constant value to subtract.

<b>Returns:</b>

FunctionExpression

A new Expression representing the subtraction operation.

Example

typescript
// Subtract 20 from the value of the 'total' field
field("total").subtract(20);

Expression.sum()

Creates an aggregation that calculates the sum of a numeric field across multiple stage inputs.

<b>Signature:</b>

typescript
sum(): AggregateFunction;

<b>Returns:</b>

AggregateFunction

A new AggregateFunction representing the 'sum' aggregation.

Example

typescript
// Calculate the total revenue from a set of orders
field("orderAmount").sum().as("totalRevenue");

Expression.timestampAdd()

Creates an expression that adds a specified amount of time to this timestamp expression.

<b>Signature:</b>

typescript
timestampAdd(unit: Expression, amount: Expression): FunctionExpression;

Parameters

ParameterTypeDescription
unitExpressionThe expression evaluates to unit of time, must be one of 'microsecond', 'millisecond', 'second', 'minute', 'hour', 'day'.
amountExpressionThe expression evaluates to amount of the unit.

<b>Returns:</b>

FunctionExpression

A new Expression representing the resulting timestamp.

Example

typescript
// Add some duration determined by field 'unit' and 'amount' to the 'timestamp' field.
field("timestamp").timestampAdd(field("unit"), field("amount"));

Expression.timestampAdd()

Creates an expression that adds a specified amount of time to this timestamp expression.

<b>Signature:</b>

typescript
timestampAdd(unit: TimeUnit, amount: number): FunctionExpression;

Parameters

ParameterTypeDescription
unitTimeUnitThe unit of time to add (e.g., "day", "hour").
amountnumberThe amount of time to add.

<b>Returns:</b>

FunctionExpression

A new Expression representing the resulting timestamp.

Example

typescript
// Add 1 day to the 'timestamp' field.
field("timestamp").timestampAdd("day", 1);

Expression.timestampDiff()

Creates an expression that calculates the difference between this timestamp and another timestamp.

<b>Signature:</b>

typescript
timestampDiff(start: Expression, unit: Expression): FunctionExpression;

Parameters

ParameterTypeDescription
startExpressionThe expression evaluating to the starting timestamp.
unitExpressionThe expression evaluates to a unit of time, must be one of 'microsecond', 'millisecond', 'second', 'minute', 'hour', 'day'.

<b>Returns:</b>

FunctionExpression

A new Expression representing the difference as an integer.

Example

typescript
// Calculate the difference determined by fields 'startTime' and 'unit'.
field("endTime").timestampDiff(field("startTime"), field("unit"));

Expression.timestampDiff()

Creates an expression that calculates the difference between this timestamp and another timestamp.

<b>Signature:</b>

typescript
timestampDiff(start: string | Expression, unit: TimeUnit): FunctionExpression;

Parameters

ParameterTypeDescription
startstring | ExpressionThe field name of the starting timestamp.
unitTimeUnitThe unit of time for the difference (e.g., "day", "hour").

<b>Returns:</b>

FunctionExpression

A new Expression representing the difference as an integer.

Example

typescript
// Calculate the difference in days between 'endTime' and 'startTime' fields.
field("endTime").timestampDiff("startTime", "day");

Expression.timestampExtract()

Creates an expression that extracts a specified part from this timestamp expression.

<b>Signature:</b>

typescript
timestampExtract(part: TimePart, timezone?: string | Expression): FunctionExpression;

Parameters

ParameterTypeDescription
partTimePartThe part to extract from the timestamp (e.g., "year", "month", "day").
timezonestring | ExpressionThe timezone to use for extraction. Valid values are from the TZ database (e.g., "America/Los_Angeles") or in the format "Etc/GMT-1."

<b>Returns:</b>

FunctionExpression

A new Expression representing the extracted part as an integer.

Example

typescript
// Extract the year from the 'createdAt' field.
field('createdAt').timestampExtract('year')

Expression.timestampExtract()

Creates an expression that extracts a specified part from this timestamp expression.

<b>Signature:</b>

typescript
timestampExtract(part: Expression, timezone?: string | Expression): FunctionExpression;

Parameters

ParameterTypeDescription
partExpressionThe expression evaluating to the part to extract.
timezonestring | ExpressionThe timezone to use for extraction. Valid values are from the TZ database (e.g., "America/Los_Angeles") or in the format "Etc/GMT-1."

<b>Returns:</b>

FunctionExpression

A new Expression representing the extracted part as an integer.

Example

typescript
// Extract the part specified by the field 'extractionPart' from 'createdAt'.
field('createdAt').timestampExtract(field('extractionPart'))

Expression.timestampSubtract()

Creates an expression that subtracts a specified amount of time from this timestamp expression.

<b>Signature:</b>

typescript
timestampSubtract(unit: Expression, amount: Expression): FunctionExpression;

Parameters

ParameterTypeDescription
unitExpressionThe expression evaluates to unit of time, must be one of 'microsecond', 'millisecond', 'second', 'minute', 'hour', 'day'.
amountExpressionThe expression evaluates to amount of the unit.

<b>Returns:</b>

FunctionExpression

A new Expression representing the resulting timestamp.

Example

typescript
// Subtract some duration determined by field 'unit' and 'amount' from the 'timestamp' field.
field("timestamp").timestampSubtract(field("unit"), field("amount"));

Expression.timestampSubtract()

Creates an expression that subtracts a specified amount of time from this timestamp expression.

<b>Signature:</b>

typescript
timestampSubtract(unit: TimeUnit, amount: number): FunctionExpression;

Parameters

ParameterTypeDescription
unitTimeUnitThe unit of time to subtract (e.g., "day", "hour").
amountnumberThe amount of time to subtract.

<b>Returns:</b>

FunctionExpression

A new Expression representing the resulting timestamp.

Example

typescript
// Subtract 1 day from the 'timestamp' field.
field("timestamp").timestampSubtract("day", 1);

Expression.timestampToUnixMicros()

Creates an expression that converts this timestamp expression to the number of microseconds since the Unix epoch (1970-01-01 00:00:00 UTC).

<b>Signature:</b>

typescript
timestampToUnixMicros(): FunctionExpression;

<b>Returns:</b>

FunctionExpression

A new Expression representing the number of microseconds since epoch.

Example

typescript
// Convert the 'timestamp' field to microseconds since epoch.
field("timestamp").timestampToUnixMicros();

Expression.timestampToUnixMillis()

Creates an expression that converts this timestamp expression to the number of milliseconds since the Unix epoch (1970-01-01 00:00:00 UTC).

<b>Signature:</b>

typescript
timestampToUnixMillis(): FunctionExpression;

<b>Returns:</b>

FunctionExpression

A new Expression representing the number of milliseconds since epoch.

Example

typescript
// Convert the 'timestamp' field to milliseconds since epoch.
field("timestamp").timestampToUnixMillis();

Expression.timestampToUnixSeconds()

Creates an expression that converts this timestamp expression to the number of seconds since the Unix epoch (1970-01-01 00:00:00 UTC).

<b>Signature:</b>

typescript
timestampToUnixSeconds(): FunctionExpression;

<b>Returns:</b>

FunctionExpression

A new Expression representing the number of seconds since epoch.

Example

typescript
// Convert the 'timestamp' field to seconds since epoch.
field("timestamp").timestampToUnixSeconds();

Expression.timestampTruncate()

Creates an expression that truncates a timestamp to a specified granularity.

<b>Signature:</b>

typescript
timestampTruncate(granularity: TimeGranularity, timezone?: string | Expression): FunctionExpression;

Parameters

ParameterTypeDescription
granularityTimeGranularityThe granularity to truncate to.
timezonestring | ExpressionThe timezone to use for truncation. Valid values are from the TZ database (e.g., "America/Los_Angeles") or in the format "Etc/GMT-1".

<b>Returns:</b>

FunctionExpression

A new Expression representing the truncated timestamp.

Example

typescript
// Truncate the 'createdAt' timestamp to the beginning of the day.
field('createdAt').timestampTruncate('day')

Expression.timestampTruncate()

Creates an expression that truncates a timestamp to a specified granularity.

<b>Signature:</b>

typescript
timestampTruncate(granularity: Expression, timezone?: string | Expression): FunctionExpression;

Parameters

ParameterTypeDescription
granularityExpressionThe granularity to truncate to.
timezonestring | ExpressionThe timezone to use for truncation. Valid values are from the TZ database (e.g., "America/Los_Angeles") or in the format "Etc/GMT-1".

<b>Returns:</b>

FunctionExpression

A new Expression representing the truncated timestamp.

Example

typescript
// Truncate the 'createdAt' timestamp to the granularity specified in the field 'granularity'.
field('createdAt').timestampTruncate(field('granularity'))

Expression.toLower()

Creates an expression that converts a string to lowercase.

<b>Signature:</b>

typescript
toLower(): FunctionExpression;

<b>Returns:</b>

FunctionExpression

A new Expression representing the lowercase string.

Example

typescript
// Convert the 'name' field to lowercase
field("name").toLower();

Expression.toUpper()

Creates an expression that converts a string to uppercase.

<b>Signature:</b>

typescript
toUpper(): FunctionExpression;

<b>Returns:</b>

FunctionExpression

A new Expression representing the uppercase string.

Example

typescript
// Convert the 'title' field to uppercase
field("title").toUpper();

Expression.trim()

Creates an expression that removes leading and trailing characters from a string or byte array.

<b>Signature:</b>

typescript
trim(valueToTrim?: string | Expression | Bytes): FunctionExpression;

Parameters

ParameterTypeDescription
valueToTrimstring | Expression | BytesOptional This parameter is treated as a set of characters or bytes that will be trimmed from the input. If not specified, then whitespace will be trimmed.

<b>Returns:</b>

FunctionExpression

A new Expression representing the trimmed string or byte array.

Example

typescript
// Trim whitespace from the 'userInput' field
field("userInput").trim();

// Trim quotes from the 'userInput' field
field("userInput").trim('"');

Expression.trunc()

Creates an expression that truncates the numeric value to an integer.

<b>Signature:</b>

typescript
trunc(): FunctionExpression;

<b>Returns:</b>

FunctionExpression

A new Expression representing the truncated value.

Example

typescript
// Truncate the 'rating' field
field("rating").trunc();

Expression.trunc()

Creates an expression that truncates a numeric value to the specified number of decimal places.

<b>Signature:</b>

typescript
trunc(decimalPlaces: number): FunctionExpression;

Parameters

ParameterTypeDescription
decimalPlacesnumberA constant specifying the truncation precision in decimal places.

<b>Returns:</b>

FunctionExpression

A new Expression representing the truncated value.

Example

typescript
// Truncate the value of the 'rating' field to two decimal places.
field("rating").trunc(2);

Expression.trunc()

Creates an expression that truncates a numeric value to the specified number of decimal places.

<b>Signature:</b>

typescript
trunc(decimalPlaces: Expression): FunctionExpression;

Parameters

ParameterTypeDescription
decimalPlacesExpressionAn expression specifying the truncation precision in decimal places.

<b>Returns:</b>

FunctionExpression

A new Expression representing the truncated value.

Example

typescript
// Truncate the value of the 'rating' field to two decimal places.
field("rating").trunc(constant(2));

Expression.type()

Creates an expression that returns the data type of this expression's result, as a string.

This is evaluated on the backend. This means: 1. Generic typed elements (like array<string><!-- -->) evaluate strictly to the primitive 'array'<!-- -->. 2. Any custom FirestoreDataConverter mappings are ignored. 3. For numeric values, the backend does not yield the JavaScript "number" type; it evaluates precisely as "int64" or "float64"<!-- -->. 4. For date or timestamp objects, the backend evaluates to "timestamp"<!-- -->.

<b>Signature:</b>

typescript
type(): FunctionExpression;

<b>Returns:</b>

FunctionExpression

A new Expression representing the data type.

Example

typescript
// Get the data type of the value in field 'title'
field('title').type()

Expression.unixMicrosToTimestamp()

Creates an expression that interprets this expression as the number of microseconds since the Unix epoch (1970-01-01 00:00:00 UTC) and returns a timestamp.

<b>Signature:</b>

typescript
unixMicrosToTimestamp(): FunctionExpression;

<b>Returns:</b>

FunctionExpression

A new Expression representing the timestamp.

Example

typescript
// Interpret the 'microseconds' field as microseconds since epoch.
field("microseconds").unixMicrosToTimestamp();

Expression.unixMillisToTimestamp()

Creates an expression that interprets this expression as the number of milliseconds since the Unix epoch (1970-01-01 00:00:00 UTC) and returns a timestamp.

<b>Signature:</b>

typescript
unixMillisToTimestamp(): FunctionExpression;

<b>Returns:</b>

FunctionExpression

A new Expression representing the timestamp.

Example

typescript
// Interpret the 'milliseconds' field as milliseconds since epoch.
field("milliseconds").unixMillisToTimestamp();

Expression.unixSecondsToTimestamp()

Creates an expression that interprets this expression as the number of seconds since the Unix epoch (1970-01-01 00:00:00 UTC) and returns a timestamp.

<b>Signature:</b>

typescript
unixSecondsToTimestamp(): FunctionExpression;

<b>Returns:</b>

FunctionExpression

A new Expression representing the timestamp.

Example

typescript
// Interpret the 'seconds' field as seconds since epoch.
field("seconds").unixSecondsToTimestamp();

Expression.vectorLength()

Creates an expression that calculates the length (number of dimensions) of this Firestore Vector expression.

<b>Signature:</b>

typescript
vectorLength(): FunctionExpression;

<b>Returns:</b>

FunctionExpression

A new Expression representing the length of the vector.

Example

typescript
// Get the vector length (dimension) of the field 'embedding'.
field("embedding").vectorLength();