Expression class

This API is provided as a preview for developers and may change based on feedback that we receive. Do not use this API in a production environment.

Represents an expression that can be evaluated to a value within the execution of aPipeline.

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.

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

Signature:

exportdeclareabstractclassExpression

Properties

PropertyModifiersTypeDescription
expressionTypeExpressionType(Public Preview)

Methods

MethodModifiersDescription
abs()(Public Preview) Creates an expression that computes the absolute value of a numeric value.
add(second)(Public Preview) Creates an expression that adds this expression to another expression.
arrayConcat(secondArray, otherArrays)(Public Preview) Creates an expression that concatenates an array expression with one or more other arrays.
arrayContains(expression)(Public Preview) Creates an expression that checks if an array contains a specific element.
arrayContains(value)(Public Preview) Creates an expression that checks if an array contains a specific value.
arrayContainsAll(values)(Public Preview) Creates an expression that checks if an array contains all the specified elements.
arrayContainsAll(arrayExpression)(Public Preview) Creates an expression that checks if an array contains all the specified elements.
arrayContainsAny(values)(Public Preview) Creates an expression that checks if an array contains any of the specified elements.
arrayContainsAny(arrayExpression)(Public Preview) Creates an expression that checks if an array contains any of the specified elements.
arrayGet(offset)(Public Preview) 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)(Public Preview) 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.
arrayLength()(Public Preview) Creates an expression that calculates the length of an array.
arrayReverse()(Public Preview) Creates an expression that reverses an array.
arraySum()(Public Preview) Creates an expression that computes the sum of the elements in an array.
as(name)(Public Preview) 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()(Public Preview) Wraps the expression in a [BooleanExpression].
ascending()(Public Preview) Creates anOrdering that sorts documents in ascending order based on this expression.
average()(Public Preview) Creates an aggregation that calculates the average (mean) of a numeric field across multiple stage inputs.
byteLength()(Public Preview) Creates an expression that calculates the length of this string expression in bytes.
ceil()(Public Preview) Creates an expression that computes the ceiling of a numeric value.
charLength()(Public Preview) Creates an expression that calculates the character length of a string in UTF-8.
collectionId()(Public Preview) Creates an expression that returns the collection ID from a path.
concat(second, others)(Public Preview) Creates an expression that concatenates expression results together.
cosineDistance(vectorExpression)(Public Preview) Calculates the cosine distance between two vectors.
cosineDistance(vector)(Public Preview) Calculates the Cosine distance between two vectors.
count()(Public Preview) Creates an aggregation that counts the number of stage inputs with valid evaluations of the expression or field.
countDistinct()(Public Preview) Creates an aggregation that counts the number of distinct values of the expression or field.
descending()(Public Preview) Creates anOrdering that sorts documents in descending order based on this expression.
divide(divisor)(Public Preview) Creates an expression that divides this expression by another expression.
divide(divisor)(Public Preview) Creates an expression that divides this expression by a constant value.
documentId()(Public Preview) Creates an expression that returns the document ID from a path.
dotProduct(vectorExpression)(Public Preview) Calculates the dot product between two vectors.
dotProduct(vector)(Public Preview) Calculates the dot product between two vectors.
endsWith(suffix)(Public Preview) Creates an expression that checks if a string ends with a given postfix.
endsWith(suffix)(Public Preview) Creates an expression that checks if a string ends with a given postfix (represented as an expression).
equal(expression)(Public Preview) Creates an expression that checks if this expression is equal to another expression.
equal(value)(Public Preview) Creates an expression that checks if this expression is equal to a constant value.
equalAny(values)(Public Preview) Creates an expression that checks if this expression is equal to any of the provided values or expressions.
equalAny(arrayExpression)(Public Preview) Creates an expression that checks if this expression is equal to any of the provided values or expressions.
euclideanDistance(vectorExpression)(Public Preview) Calculates the Euclidean distance between two vectors.
euclideanDistance(vector)(Public Preview) Calculates the Euclidean distance between two vectors.
exists()(Public Preview) Creates an expression that checks if a field exists in the document.
exp()(Public Preview) Creates an expression that computes e to the power of this expression.
floor()(Public Preview) Creates an expression that computes the floor of a numeric value.
greaterThan(expression)(Public Preview) Creates an expression that checks if this expression is greater than another expression.
greaterThan(value)(Public Preview) Creates an expression that checks if this expression is greater than a constant value.
greaterThanOrEqual(expression)(Public Preview) Creates an expression that checks if this expression is greater than or equal to another expression.
greaterThanOrEqual(value)(Public Preview) Creates an expression that checks if this expression is greater than or equal to a constant value.
ifAbsent(elseValue)(Public Preview) Creates an expression that returns theelseValue argument if this expression results in an absent value, else return the result of the this expression evaluation.
ifAbsent(elseExpression)(Public Preview) Creates an expression that returns theelseValue argument if this expression results in an absent value, else return the result of this expression evaluation.
// Returns the value of the optional field 'optional_field', or if that is// absent, then returns the value of the field `field("optional_field").ifAbsent(field('default_field'))

||ifError(catchExpr) | |(Public Preview) Creates an expression that returns the result of thecatchExpr argument if there is an error, else return the result of this expression. ||ifError(catchValue) | |(Public Preview) Creates an expression that returns thecatch argument if there is an error, else return the result of this expression. ||isAbsent() | |(Public Preview) Creates an expression that returnstrue if the result of this expression is absent. Otherwise, returnsfalse even if the value isnull. ||isError() | |(Public Preview) Creates an expression that checks if a given expression produces an error. ||join(delimiterExpression) | |(Public Preview) Creates an expression that joins the elements of an array into a string. ||join(delimiter) | |(Public Preview) Creates an expression that joins the elements of an array field into a string. ||length() | |(Public Preview) Creates an expression that calculates the length of a string, array, map, vector, or bytes. ||lessThan(experession) | |(Public Preview) Creates an expression that checks if this expression is less than another expression. ||lessThan(value) | |(Public Preview) Creates an expression that checks if this expression is less than a constant value. ||lessThanOrEqual(expression) | |(Public Preview) Creates an expression that checks if this expression is less than or equal to another expression. ||lessThanOrEqual(value) | |(Public Preview) Creates an expression that checks if this expression is less than or equal to a constant value. ||like(pattern) | |(Public Preview) Creates an expression that performs a case-sensitive string comparison. ||like(pattern) | |(Public Preview) Creates an expression that performs a case-sensitive string comparison. ||ln() | |(Public Preview) Creates an expression that computes the natural logarithm of a numeric value. ||log10() | |(Public Preview) Creates an expression that computes the base-10 logarithm of a numeric value. ||logicalMaximum(second, others) | |(Public Preview) Creates an expression that returns the larger value between this expression and another expression, based on Firestore's value type ordering. ||logicalMinimum(second, others) | |(Public Preview) Creates an expression that returns the smaller value between this expression and another expression, based on Firestore's value type ordering. ||mapGet(subfield) | |(Public Preview) Accesses a value from a map (object) field using the provided key. ||mapMerge(secondMap, otherMaps) | |(Public Preview) Creates an expression that merges multiple map values. ||mapRemove(key) | |(Public Preview) Creates an expression that removes a key from the map produced by evaluating this expression. ||mapRemove(keyExpr) | |(Public Preview) Creates an expression that removes a key from the map produced by evaluating this expression. ||maximum() | |(Public Preview) Creates an aggregation that finds the maximum value of a field across multiple stage inputs. ||minimum() | |(Public Preview) Creates an aggregation that finds the minimum value of a field across multiple stage inputs. ||mod(expression) | |(Public Preview) Creates an expression that calculates the modulo (remainder) of dividing this expression by another expression. ||mod(value) | |(Public Preview) Creates an expression that calculates the modulo (remainder) of dividing this expression by a constant value. ||multiply(second) | |(Public Preview) Creates an expression that multiplies this expression by another expression. ||notEqual(expression) | |(Public Preview) Creates an expression that checks if this expression is not equal to another expression. ||notEqual(value) | |(Public Preview) Creates an expression that checks if this expression is not equal to a constant value. ||notEqualAny(values) | |(Public Preview) Creates an expression that checks if this expression is not equal to any of the provided values or expressions. ||notEqualAny(arrayExpression) | |(Public Preview) Creates an expression that checks if this expression is not equal to any of the values in the evaluated expression. ||pow(exponent) | |(Public Preview) Creates an expression that returns the value of this expression raised to the power of another expression. ||pow(exponent) | |(Public Preview) Creates an expression that returns the value of this expression raised to the power of a constant value. ||regexContains(pattern) | |(Public Preview) Creates an expression that checks if a string contains a specified regular expression as a substring. ||regexContains(pattern) | |(Public Preview) Creates an expression that checks if a string contains a specified regular expression as a substring. ||regexFind(pattern) | |(Public Preview) Creates an expression that returns the first substring of a string expression that matches a specified regular expression.This expression uses theRE2 regular expression syntax. ||regexFind(pattern) | |(Public Preview) Creates an expression that returns the first substring of a string expression that matches a specified regular expression.This expression uses theRE2 regular expression syntax. ||regexFindAll(pattern) | |(Public Preview) Creates an expression that evaluates to a list of all substrings in this string expression that match a specified regular expression.This expression uses theRE2 regular expression syntax. ||regexFindAll(pattern) | |(Public Preview) Creates an expression that evaluates to a list of all substrings in this string expression that match a specified regular expression.This expression uses theRE2 regular expression syntax. ||regexMatch(pattern) | |(Public Preview) Creates an expression that checks if a string matches a specified regular expression. ||regexMatch(pattern) | |(Public Preview) Creates an expression that checks if a string matches a specified regular expression. ||reverse() | |(Public Preview) Creates an expression that reverses this string expression. ||round() | |(Public Preview) Creates an expression that rounds a numeric value to the nearest whole number. ||round(decimalPlaces) | |(Public Preview) Creates an expression that rounds a numeric value to the specified number of decimal places. ||round(decimalPlaces) | |(Public Preview) Creates an expression that rounds a numeric value to the specified number of decimal places. ||split(delimiter) | |(Public Preview) Creates an expression that splits the result of this expression into an array of substrings based on the provided delimiter. ||split(delimiter) | |(Public Preview) Creates an expression that splits the result of this expression into an array of substrings based on the provided delimiter. ||sqrt() | |(Public Preview) Creates an expression that computes the square root of a numeric value. ||startsWith(prefix) | |(Public Preview) Creates an expression that checks if a string starts with a given prefix. ||startsWith(prefix) | |(Public Preview) Creates an expression that checks if a string starts with a given prefix (represented as an expression). ||stringConcat(secondString, otherStrings) | |(Public Preview) Creates an expression that concatenates string expressions together. ||stringContains(substring) | |(Public Preview) Creates an expression that checks if a string contains a specified substring. ||stringContains(expr) | |(Public Preview) Creates an expression that checks if a string contains the string represented by another expression. ||stringReverse() | |(Public Preview) Creates an expression that reverses a string. ||substring(position, length) | |(Public Preview) Creates an expression that returns a substring of the results of this expression. ||substring(position, length) | |(Public Preview) Creates an expression that returns a substring of the results of this expression. ||subtract(subtrahend) | |(Public Preview) Creates an expression that subtracts another expression from this expression. ||subtract(subtrahend) | |(Public Preview) Creates an expression that subtracts a constant value from this expression. ||sum() | |(Public Preview) Creates an aggregation that calculates the sum of a numeric field across multiple stage inputs. ||timestampAdd(unit, amount) | |(Public Preview) Creates an expression that adds a specified amount of time to this timestamp expression. ||timestampAdd(unit, amount) | |(Public Preview) Creates an expression that adds a specified amount of time to this timestamp expression. ||timestampSubtract(unit, amount) | |(Public Preview) Creates an expression that subtracts a specified amount of time from this timestamp expression. ||timestampSubtract(unit, amount) | |(Public Preview) Creates an expression that subtracts a specified amount of time from this timestamp expression. ||timestampToUnixMicros() | |(Public Preview) 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() | |(Public Preview) 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() | |(Public Preview) 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) | |(Public Preview) Creates an expression that truncates a timestamp to a specified granularity. ||timestampTruncate(granularity, timezone) | |(Public Preview) Creates an expression that truncates a timestamp to a specified granularity. ||toLower() | |(Public Preview) Creates an expression that converts a string to lowercase. ||toUpper() | |(Public Preview) Creates an expression that converts a string to uppercase. ||trim(valueToTrim) | |(Public Preview) Creates an expression that removes leading and trailing characters from a string or byte array. ||type() | |(Public Preview) Creates an expression that returns the data type of this expression's result, as a string. ||unixMicrosToTimestamp() | |(Public Preview) 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() | |(Public Preview) 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() | |(Public Preview) 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() | |(Public Preview) Creates an expression that calculates the length (number of dimensions) of this Firestore Vector expression. |

Expression.expressionType

This API is provided as a preview for developers and may change based on feedback that we receive. Do not use this API in a production environment.

Signature:

abstractreadonlyexpressionType:ExpressionType;

Expression.abs()

This API is provided as a preview for developers and may change based on feedback that we receive. Do not use this API in a production environment.

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

Signature:

abs():FunctionExpression;

Returns:

FunctionExpression

A newExpression representing the absolute value of the numeric value.

Example

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

Expression.add()

This API is provided as a preview for developers and may change based on feedback that we receive. Do not use this API in a production environment.

Creates an expression that adds this expression to another expression.

Signature:

add(second:Expression|unknown):FunctionExpression;

Parameters

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

Returns:

FunctionExpression

A newExpression representing the addition operation.

Example

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

Expression.arrayConcat()

This API is provided as a preview for developers and may change based on feedback that we receive. Do not use this API in a production environment.

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

Signature:

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.

Returns:

FunctionExpression

A newExpression representing the concatenated array.

Example

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

Expression.arrayContains()

This API is provided as a preview for developers and may change based on feedback that we receive. Do not use this API in a production environment.

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

Signature:

arrayContains(expression:Expression):BooleanExpression;

Parameters

ParameterTypeDescription
expressionExpressionThe element to search for in the array.

Returns:

BooleanExpression

A newExpression representing the 'array_contains' comparison.

Example

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

Expression.arrayContains()

This API is provided as a preview for developers and may change based on feedback that we receive. Do not use this API in a production environment.

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

Signature:

arrayContains(value:unknown):BooleanExpression;

Parameters

ParameterTypeDescription
valueunknownThe element to search for in the array.

Returns:

BooleanExpression

A newExpression representing the 'array_contains' comparison.

Example

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

Expression.arrayContainsAll()

This API is provided as a preview for developers and may change based on feedback that we receive. Do not use this API in a production environment.

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

Signature:

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

Parameters

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

Returns:

BooleanExpression

A newExpression representing the 'array_contains_all' comparison.

Example

// 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()

This API is provided as a preview for developers and may change based on feedback that we receive. Do not use this API in a production environment.

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

Signature:

arrayContainsAll(arrayExpression:Expression):BooleanExpression;

Parameters

ParameterTypeDescription
arrayExpressionExpressionThe elements to check for in the array.

Returns:

BooleanExpression

A newExpression representing the 'array_contains_all' comparison.

Example

// 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()

This API is provided as a preview for developers and may change based on feedback that we receive. Do not use this API in a production environment.

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

Signature:

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

Parameters

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

Returns:

BooleanExpression

A newExpression representing the 'array_contains_any' comparison.

Example

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

Expression.arrayContainsAny()

This API is provided as a preview for developers and may change based on feedback that we receive. Do not use this API in a production environment.

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

Signature:

arrayContainsAny(arrayExpression:Expression):BooleanExpression;

Parameters

ParameterTypeDescription
arrayExpressionExpressionThe elements to check for in the array.

Returns:

BooleanExpression

A newExpression representing the 'array_contains_any' comparison.

Example

// 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.arrayGet()

This API is provided as a preview for developers and may change based on feedback that we receive. Do not use this API in a production environment.

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.

Signature:

arrayGet(offset:number):FunctionExpression;

Parameters

ParameterTypeDescription
offsetnumberThe index of the element to return.

Returns:

FunctionExpression

A newExpression representing the 'arrayGet' operation.

Example

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

Expression.arrayGet()

This API is provided as a preview for developers and may change based on feedback that we receive. Do not use this API in a production environment.

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.

Signature:

arrayGet(offsetExpr:Expression):FunctionExpression;

Parameters

ParameterTypeDescription
offsetExprExpressionAnExpression evaluating to the index of the element to return.

Returns:

FunctionExpression

A newExpression representing the 'arrayGet' operation.

Example

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

Expression.arrayLength()

This API is provided as a preview for developers and may change based on feedback that we receive. Do not use this API in a production environment.

Creates an expression that calculates the length of an array.

Signature:

arrayLength():FunctionExpression;

Returns:

FunctionExpression

A newExpression representing the length of the array.

Example

// Get the number of items in the 'cart' arrayfield("cart").arrayLength();

Expression.arrayReverse()

This API is provided as a preview for developers and may change based on feedback that we receive. Do not use this API in a production environment.

Creates an expression that reverses an array.

Signature:

arrayReverse():FunctionExpression;

Returns:

FunctionExpression

A newExpression representing the reversed array.

Example

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

Expression.arraySum()

This API is provided as a preview for developers and may change based on feedback that we receive. Do not use this API in a production environment.

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

Signature:

arraySum():FunctionExpression;

Returns:

FunctionExpression

A newExpression representing the sum of the elements in the array.

Example

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

Expression.as()

This API is provided as a preview for developers and may change based on feedback that we receive. Do not use this API in a production environment.

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.

Signature:

as(name:string):AliasedExpression;

Parameters

ParameterTypeDescription
namestringThe alias to assign to this expression.

Returns:

AliasedExpression

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

Example

// 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()

This API is provided as a preview for developers and may change based on feedback that we receive. Do not use this API in a production environment.

Wraps the expression in a [BooleanExpression].

Signature:

asBoolean():BooleanExpression;

Returns:

BooleanExpression

A [BooleanExpression] representing the same expression.

Expression.ascending()

This API is provided as a preview for developers and may change based on feedback that we receive. Do not use this API in a production environment.

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

Signature:

ascending():Ordering;

Returns:

Ordering

A newOrdering for ascending sorting.

Example

// Sort documents by the 'name' field in ascending orderpipeline().collection("users").sort(field("name").ascending());

Expression.average()

This API is provided as a preview for developers and may change based on feedback that we receive. Do not use this API in a production environment.

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

Signature:

average():AggregateFunction;

Returns:

AggregateFunction

A newAggregateFunction representing the 'average' aggregation.

Example

// Calculate the average age of usersfield("age").average().as("averageAge");

Expression.byteLength()

This API is provided as a preview for developers and may change based on feedback that we receive. Do not use this API in a production environment.

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

Signature:

byteLength():FunctionExpression;

Returns:

FunctionExpression

A newExpression representing the length of the string in bytes.

Example

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

Expression.ceil()

This API is provided as a preview for developers and may change based on feedback that we receive. Do not use this API in a production environment.

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

Signature:

ceil():FunctionExpression;

Returns:

FunctionExpression

A newExpression representing the ceiling of the numeric value.

Example

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

Expression.charLength()

This API is provided as a preview for developers and may change based on feedback that we receive. Do not use this API in a production environment.

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

Signature:

charLength():FunctionExpression;

Returns:

FunctionExpression

A newExpression representing the length of the string.

Example

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

Expression.collectionId()

This API is provided as a preview for developers and may change based on feedback that we receive. Do not use this API in a production environment.

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

Signature:

collectionId():FunctionExpression;

Returns:

FunctionExpression

A newExpression representing the collectionId operation.

Example

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

Expression.concat()

This API is provided as a preview for developers and may change based on feedback that we receive. Do not use this API in a production environment.

Creates an expression that concatenates expression results together.

Signature:

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.

Returns:

FunctionExpression

A newExpression representing the concatenated value.

Example

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

Expression.cosineDistance()

This API is provided as a preview for developers and may change based on feedback that we receive. Do not use this API in a production environment.

Calculates the cosine distance between two vectors.

Signature:

cosineDistance(vectorExpression:Expression):FunctionExpression;

Parameters

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

Returns:

FunctionExpression

A newExpression representing the cosine distance between the two vectors.

Example

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

Expression.cosineDistance()

This API is provided as a preview for developers and may change based on feedback that we receive. Do not use this API in a production environment.

Calculates the Cosine distance between two vectors.

Signature:

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

Parameters

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

Returns:

FunctionExpression

A newExpression representing the Cosine* distance between the two vectors.

Example

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

Expression.count()

This API is provided as a preview for developers and may change based on feedback that we receive. Do not use this API in a production environment.

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

Signature:

count():AggregateFunction;

Returns:

AggregateFunction

A newAggregateFunction representing the 'count' aggregation.

Example

// Count the total number of productsfield("productId").count().as("totalProducts");

Expression.countDistinct()

This API is provided as a preview for developers and may change based on feedback that we receive. Do not use this API in a production environment.

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

Signature:

countDistinct():AggregateFunction;

Returns:

AggregateFunction

A newAggregateFunction representing the 'count_distinct' aggregation.

Example

// Count the distinct number of productsfield("productId").countDistinct().as("distinctProducts");

Expression.descending()

This API is provided as a preview for developers and may change based on feedback that we receive. Do not use this API in a production environment.

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

Signature:

descending():Ordering;

Returns:

Ordering

A newOrdering for descending sorting.

Example

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

Expression.divide()

This API is provided as a preview for developers and may change based on feedback that we receive. Do not use this API in a production environment.

Creates an expression that divides this expression by another expression.

Signature:

divide(divisor:Expression):FunctionExpression;

Parameters

ParameterTypeDescription
divisorExpressionThe expression to divide by.

Returns:

FunctionExpression

A newExpression representing the division operation.

Example

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

Expression.divide()

This API is provided as a preview for developers and may change based on feedback that we receive. Do not use this API in a production environment.

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

Signature:

divide(divisor:number):FunctionExpression;

Parameters

ParameterTypeDescription
divisornumberThe constant value to divide by.

Returns:

FunctionExpression

A newExpression representing the division operation.

Example

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

Expression.documentId()

This API is provided as a preview for developers and may change based on feedback that we receive. Do not use this API in a production environment.

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

Signature:

documentId():FunctionExpression;

Returns:

FunctionExpression

A newExpression representing the documentId operation.

Example

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

Expression.dotProduct()

This API is provided as a preview for developers and may change based on feedback that we receive. Do not use this API in a production environment.

Calculates the dot product between two vectors.

Signature:

dotProduct(vectorExpression:Expression):FunctionExpression;

Parameters

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

Returns:

FunctionExpression

A newExpression representing the dot product between the two vectors.

Example

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

Expression.dotProduct()

This API is provided as a preview for developers and may change based on feedback that we receive. Do not use this API in a production environment.

Calculates the dot product between two vectors.

Signature:

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

Parameters

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

Returns:

FunctionExpression

A newExpression representing the dot product between the two vectors.

Example

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

Expression.endsWith()

This API is provided as a preview for developers and may change based on feedback that we receive. Do not use this API in a production environment.

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

Signature:

endsWith(suffix:string):BooleanExpression;

Parameters

ParameterTypeDescription
suffixstringThe postfix to check for.

Returns:

BooleanExpression

A newExpression representing the 'ends with' comparison.

Example

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

Expression.endsWith()

This API is provided as a preview for developers and may change based on feedback that we receive. Do not use this API in a production environment.

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

Signature:

endsWith(suffix:Expression):BooleanExpression;

Parameters

ParameterTypeDescription
suffixExpressionThe postfix expression to check for.

Returns:

BooleanExpression

A newExpression representing the 'ends with' comparison.

Example

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

Expression.equal()

This API is provided as a preview for developers and may change based on feedback that we receive. Do not use this API in a production environment.

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

Signature:

equal(expression:Expression):BooleanExpression;

Parameters

ParameterTypeDescription
expressionExpressionThe expression to compare for equality.

Returns:

BooleanExpression

A newExpression representing the equality comparison.

Example

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

Expression.equal()

This API is provided as a preview for developers and may change based on feedback that we receive. Do not use this API in a production environment.

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

Signature:

equal(value:unknown):BooleanExpression;

Parameters

ParameterTypeDescription
valueunknownThe constant value to compare for equality.

Returns:

BooleanExpression

A newExpression representing the equality comparison.

Example

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

Expression.equalAny()

This API is provided as a preview for developers and may change based on feedback that we receive. Do not use this API in a production environment.

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

Signature:

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

Parameters

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

Returns:

BooleanExpression

A newExpression representing the 'IN' comparison.

Example

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

Expression.equalAny()

This API is provided as a preview for developers and may change based on feedback that we receive. Do not use this API in a production environment.

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

Signature:

equalAny(arrayExpression:Expression):BooleanExpression;

Parameters

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

Returns:

BooleanExpression

A newExpression representing the 'IN' comparison.

Example

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

Expression.euclideanDistance()

This API is provided as a preview for developers and may change based on feedback that we receive. Do not use this API in a production environment.

Calculates the Euclidean distance between two vectors.

Signature:

euclideanDistance(vectorExpression:Expression):FunctionExpression;

Parameters

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

Returns:

FunctionExpression

A newExpression representing the Euclidean distance between the two vectors.

Example

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

Expression.euclideanDistance()

This API is provided as a preview for developers and may change based on feedback that we receive. Do not use this API in a production environment.

Calculates the Euclidean distance between two vectors.

Signature:

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

Parameters

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

Returns:

FunctionExpression

A newExpression representing the Euclidean distance between the two vectors.

Example

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

Expression.exists()

This API is provided as a preview for developers and may change based on feedback that we receive. Do not use this API in a production environment.

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

Signature:

exists():BooleanExpression;

Returns:

BooleanExpression

A newExpression representing the 'exists' check.

Example

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

Expression.exp()

This API is provided as a preview for developers and may change based on feedback that we receive. Do not use this API in a production environment.

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

Signature:

exp():FunctionExpression;

Returns:

FunctionExpression

A newExpression representing the exp of the numeric value.

Example

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

Expression.floor()

This API is provided as a preview for developers and may change based on feedback that we receive. Do not use this API in a production environment.

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

Signature:

floor():FunctionExpression;

Returns:

FunctionExpression

A newExpression representing the floor of the numeric value.

Example

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

Expression.greaterThan()

This API is provided as a preview for developers and may change based on feedback that we receive. Do not use this API in a production environment.

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

Signature:

greaterThan(expression:Expression):BooleanExpression;

Parameters

ParameterTypeDescription
expressionExpressionThe expression to compare for greater than.

Returns:

BooleanExpression

A newExpression representing the greater than comparison.

Example

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

Expression.greaterThan()

This API is provided as a preview for developers and may change based on feedback that we receive. Do not use this API in a production environment.

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

Signature:

greaterThan(value:unknown):BooleanExpression;

Parameters

ParameterTypeDescription
valueunknownThe constant value to compare for greater than.

Returns:

BooleanExpression

A newExpression representing the greater than comparison.

Example

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

Expression.greaterThanOrEqual()

This API is provided as a preview for developers and may change based on feedback that we receive. Do not use this API in a production environment.

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

Signature:

greaterThanOrEqual(expression:Expression):BooleanExpression;

Parameters

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

Returns:

BooleanExpression

A newExpression representing the greater than or equal to comparison.

Example

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

Expression.greaterThanOrEqual()

This API is provided as a preview for developers and may change based on feedback that we receive. Do not use this API in a production environment.

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

Signature:

greaterThanOrEqual(value:unknown):BooleanExpression;

Parameters

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

Returns:

BooleanExpression

A newExpression representing the greater than or equal to comparison.

Example

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

Expression.ifAbsent()

This API is provided as a preview for developers and may change based on feedback that we receive. Do not use this API in a production environment.

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

Signature:

ifAbsent(elseValue:unknown):Expression;

Parameters

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

Returns:

Expression

A new [Expression] representing the ifAbsent operation.

Example

// 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()

This API is provided as a preview for developers and may change based on feedback that we receive. Do not use this API in a production environment.

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

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

Signature:

ifAbsent(elseExpression:unknown):Expression;

Parameters

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

Returns:

Expression

A new [Expression] representing the ifAbsent operation.

Expression.ifError()

This API is provided as a preview for developers and may change based on feedback that we receive. Do not use this API in a production environment.

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

Signature:

ifError(catchExpr:Expression):FunctionExpression;

Parameters

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

Returns:

FunctionExpression

A newExpression representing the 'ifError' operation.

Example

// 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()

This API is provided as a preview for developers and may change based on feedback that we receive. Do not use this API in a production environment.

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

Signature:

ifError(catchValue:unknown):FunctionExpression;

Parameters

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

Returns:

FunctionExpression

A newExpression representing the 'ifError' operation.

Example

// Returns the first item in the title field arrays, or returns// "Default Title"field("title").arrayGet(0).ifError("Default Title");

Expression.isAbsent()

This API is provided as a preview for developers and may change based on feedback that we receive. Do not use this API in a production environment.

Creates an expression that returnstrue if the result of this expression is absent. Otherwise, returnsfalse even if the value isnull.

Signature:

isAbsent():BooleanExpression;

Returns:

BooleanExpression

A newBooleanExpression representing the 'isAbsent' check.

Example

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

Expression.isError()

This API is provided as a preview for developers and may change based on feedback that we receive. Do not use this API in a production environment.

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

Signature:

isError():BooleanExpression;

Returns:

BooleanExpression

A newBooleanExpression representing the 'isError' check.

Example

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

Expression.join()

This API is provided as a preview for developers and may change based on feedback that we receive. Do not use this API in a production environment.

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

Signature:

join(delimiterExpression:Expression):Expression;

Parameters

ParameterTypeDescription
delimiterExpressionExpressionThe expression that evaluates to the delimiter string.

Returns:

Expression

A new Expression representing the join operation.

Example

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

Expression.join()

This API is provided as a preview for developers and may change based on feedback that we receive. Do not use this API in a production environment.

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

Signature:

join(delimiter:string):Expression;

Parameters

ParameterTypeDescription
delimiterstringThe string to use as a delimiter.

Returns:

Expression

A new Expression representing the join operation.

Example

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

Expression.length()

This API is provided as a preview for developers and may change based on feedback that we receive. Do not use this API in a production environment.

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

Signature:

length():FunctionExpression;

Returns:

FunctionExpression

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

Example

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

Expression.lessThan()

This API is provided as a preview for developers and may change based on feedback that we receive. Do not use this API in a production environment.

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

Signature:

lessThan(experession:Expression):BooleanExpression;

Parameters

ParameterTypeDescription
experessionExpressionThe expression to compare for less than.

Returns:

BooleanExpression

A newExpression representing the less than comparison.

Example

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

Expression.lessThan()

This API is provided as a preview for developers and may change based on feedback that we receive. Do not use this API in a production environment.

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

Signature:

lessThan(value:unknown):BooleanExpression;

Parameters

ParameterTypeDescription
valueunknownThe constant value to compare for less than.

Returns:

BooleanExpression

A newExpression representing the less than comparison.

Example

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

Expression.lessThanOrEqual()

This API is provided as a preview for developers and may change based on feedback that we receive. Do not use this API in a production environment.

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

Signature:

lessThanOrEqual(expression:Expression):BooleanExpression;

Parameters

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

Returns:

BooleanExpression

A newExpression representing the less than or equal to comparison.

Example

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

Expression.lessThanOrEqual()

This API is provided as a preview for developers and may change based on feedback that we receive. Do not use this API in a production environment.

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

Signature:

lessThanOrEqual(value:unknown):BooleanExpression;

Parameters

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

Returns:

BooleanExpression

A newExpression representing the less than or equal to comparison.

Example

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

Expression.like()

This API is provided as a preview for developers and may change based on feedback that we receive. Do not use this API in a production environment.

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

Signature:

like(pattern:string):BooleanExpression;

Parameters

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

Returns:

BooleanExpression

A newExpression representing the 'like' comparison.

Example

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

Expression.like()

This API is provided as a preview for developers and may change based on feedback that we receive. Do not use this API in a production environment.

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

Signature:

like(pattern:Expression):BooleanExpression;

Parameters

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

Returns:

BooleanExpression

A newExpression representing the 'like' comparison.

Example

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

Expression.ln()

This API is provided as a preview for developers and may change based on feedback that we receive. Do not use this API in a production environment.

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

Signature:

ln():FunctionExpression;

Returns:

FunctionExpression

A newExpression representing the natural logarithm of the numeric value.

Example

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

Expression.log10()

This API is provided as a preview for developers and may change based on feedback that we receive. Do not use this API in a production environment.

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

Signature:

log10():FunctionExpression;

Returns:

FunctionExpression

A newExpression representing the base-10 logarithm of the numeric value.

Example

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

Expression.logicalMaximum()

This API is provided as a preview for developers and may change based on feedback that we receive. Do not use this API in a production environment.

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

Signature:

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.

Returns:

FunctionExpression

A newExpression representing the logical maximum operation.

Example

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

Expression.logicalMinimum()

This API is provided as a preview for developers and may change based on feedback that we receive. Do not use this API in a production environment.

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

Signature:

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.

Returns:

FunctionExpression

A newExpression representing the logical minimum operation.

Example

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

Expression.mapGet()

This API is provided as a preview for developers and may change based on feedback that we receive. Do not use this API in a production environment.

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

Signature:

mapGet(subfield:string):FunctionExpression;

Parameters

ParameterTypeDescription
subfieldstringThe key to access in the map.

Returns:

FunctionExpression

A newExpression representing the value associated with the given key in the map.

Example

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

Expression.mapMerge()

This API is provided as a preview for developers and may change based on feedback that we receive. Do not use this API in a production environment.

Creates an expression that merges multiple map values.

Signature:

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.

Returns:

FunctionExpression

A newExpression 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 expressionfield('settings').mapMerge({enabled:true},conditional(field('isAdmin'),{admin:true},{})

Expression.mapRemove()

This API is provided as a preview for developers and may change based on feedback that we receive. Do not use this API in a production environment.

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

Signature:

mapRemove(key:string):FunctionExpression;

Parameters

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

Returns:

FunctionExpression

A newExpression representing the 'mapRemove' operation.

Example

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

Expression.mapRemove()

This API is provided as a preview for developers and may change based on feedback that we receive. Do not use this API in a production environment.

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

Signature:

mapRemove(keyExpr:Expression):FunctionExpression;

Parameters

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

Returns:

FunctionExpression

A newExpression representing the 'mapRemove' operation.

Example

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

Expression.maximum()

This API is provided as a preview for developers and may change based on feedback that we receive. Do not use this API in a production environment.

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

Signature:

maximum():AggregateFunction;

Returns:

AggregateFunction

A newAggregateFunction representing the 'maximum' aggregation.

Example

// Find the highest score in a leaderboardfield("score").maximum().as("highestScore");

Expression.minimum()

This API is provided as a preview for developers and may change based on feedback that we receive. Do not use this API in a production environment.

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

Signature:

minimum():AggregateFunction;

Returns:

AggregateFunction

A newAggregateFunction representing the 'minimum' aggregation.

Example

// Find the lowest price of all productsfield("price").minimum().as("lowestPrice");

Expression.mod()

This API is provided as a preview for developers and may change based on feedback that we receive. Do not use this API in a production environment.

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

Signature:

mod(expression:Expression):FunctionExpression;

Parameters

ParameterTypeDescription
expressionExpressionThe expression to divide by.

Returns:

FunctionExpression

A newExpression representing the modulo operation.

Example

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

Expression.mod()

This API is provided as a preview for developers and may change based on feedback that we receive. Do not use this API in a production environment.

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

Signature:

mod(value:number):FunctionExpression;

Parameters

ParameterTypeDescription
valuenumberThe constant value to divide by.

Returns:

FunctionExpression

A newExpression representing the modulo operation.

Example

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

Expression.multiply()

This API is provided as a preview for developers and may change based on feedback that we receive. Do not use this API in a production environment.

Creates an expression that multiplies this expression by another expression.

Signature:

multiply(second:Expression|number):FunctionExpression;

Parameters

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

Returns:

FunctionExpression

A newExpression representing the multiplication operation.

Example

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

Expression.notEqual()

This API is provided as a preview for developers and may change based on feedback that we receive. Do not use this API in a production environment.

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

Signature:

notEqual(expression:Expression):BooleanExpression;

Parameters

ParameterTypeDescription
expressionExpressionThe expression to compare for inequality.

Returns:

BooleanExpression

A newExpression representing the inequality comparison.

Example

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

Expression.notEqual()

This API is provided as a preview for developers and may change based on feedback that we receive. Do not use this API in a production environment.

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

Signature:

notEqual(value:unknown):BooleanExpression;

Parameters

ParameterTypeDescription
valueunknownThe constant value to compare for inequality.

Returns:

BooleanExpression

A newExpression representing the inequality comparison.

Example

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

Expression.notEqualAny()

This API is provided as a preview for developers and may change based on feedback that we receive. Do not use this API in a production environment.

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

Signature:

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

Parameters

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

Returns:

BooleanExpression

A newExpression representing the 'notEqualAny' comparison.

Example

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

Expression.notEqualAny()

This API is provided as a preview for developers and may change based on feedback that we receive. Do not use this API in a production environment.

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

Signature:

notEqualAny(arrayExpression:Expression):BooleanExpression;

Parameters

ParameterTypeDescription
arrayExpressionExpressionThe values or expressions to check against.

Returns:

BooleanExpression

A newExpression representing the 'notEqualAny' comparison.

Example

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

Expression.pow()

This API is provided as a preview for developers and may change based on feedback that we receive. Do not use this API in a production environment.

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

Signature:

pow(exponent:Expression):FunctionExpression;

Parameters

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

Returns:

FunctionExpression

A newExpression representing the power operation.

Example

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

Expression.pow()

This API is provided as a preview for developers and may change based on feedback that we receive. Do not use this API in a production environment.

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

Signature:

pow(exponent:number):FunctionExpression;

Parameters

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

Returns:

FunctionExpression

A newExpression representing the power operation.

Example

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

Expression.regexContains()

This API is provided as a preview for developers and may change based on feedback that we receive. Do not use this API in a production environment.

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

Signature:

regexContains(pattern:string):BooleanExpression;

Parameters

ParameterTypeDescription
patternstringThe regular expression to use for the search.

Returns:

BooleanExpression

A newExpression representing the 'contains' comparison.

Example

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

Expression.regexContains()

This API is provided as a preview for developers and may change based on feedback that we receive. Do not use this API in a production environment.

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

Signature:

regexContains(pattern:Expression):BooleanExpression;

Parameters

ParameterTypeDescription
patternExpressionThe regular expression to use for the search.

Returns:

BooleanExpression

A newExpression representing the 'contains' comparison.

Example

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

Expression.regexFind()

This API is provided as a preview for developers and may change based on feedback that we receive. Do not use this API in a production environment.

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

This expression uses theRE2 regular expression syntax.

Signature:

regexFind(pattern:string):FunctionExpression;

Parameters

ParameterTypeDescription
patternstringThe regular expression to search for.

Returns:

FunctionExpression

A newExpression representing the regular expression find function.

Example

// Extract the domain from an email addressfield("email").regexFind("@.+")

Expression.regexFind()

This API is provided as a preview for developers and may change based on feedback that we receive. Do not use this API in a production environment.

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

This expression uses theRE2 regular expression syntax.

Signature:

regexFind(pattern:Expression):FunctionExpression;

Parameters

ParameterTypeDescription
patternExpressionThe regular expression to search for.

Returns:

FunctionExpression

A newExpression representing the regular expression find function.

Example

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

Expression.regexFindAll()

This API is provided as a preview for developers and may change based on feedback that we receive. Do not use this API in a production environment.

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

This expression uses theRE2 regular expression syntax.

Signature:

regexFindAll(pattern:string):FunctionExpression;

Parameters

ParameterTypeDescription
patternstringThe regular expression to search for.

Returns:

FunctionExpression

A newExpression that evaluates to an array of matched substrings.

Example

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

Expression.regexFindAll()

This API is provided as a preview for developers and may change based on feedback that we receive. Do not use this API in a production environment.

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

This expression uses theRE2 regular expression syntax.

Signature:

regexFindAll(pattern:Expression):FunctionExpression;

Parameters

ParameterTypeDescription
patternExpressionThe regular expression to search for.

Returns:

FunctionExpression

A newExpression that evaluates to an array of matched substrings.

Example

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

Expression.regexMatch()

This API is provided as a preview for developers and may change based on feedback that we receive. Do not use this API in a production environment.

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

Signature:

regexMatch(pattern:string):BooleanExpression;

Parameters

ParameterTypeDescription
patternstringThe regular expression to use for the match.

Returns:

BooleanExpression

A newExpression representing the regular expression match.

Example

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

Expression.regexMatch()

This API is provided as a preview for developers and may change based on feedback that we receive. Do not use this API in a production environment.

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

Signature:

regexMatch(pattern:Expression):BooleanExpression;

Parameters

ParameterTypeDescription
patternExpressionThe regular expression to use for the match.

Returns:

BooleanExpression

A newExpression representing the regular expression match.

Example

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

Expression.reverse()

This API is provided as a preview for developers and may change based on feedback that we receive. Do not use this API in a production environment.

Creates an expression that reverses this string expression.

Signature:

reverse():FunctionExpression;

Returns:

FunctionExpression

A newExpression representing the reversed string.

Example

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

Expression.round()

This API is provided as a preview for developers and may change based on feedback that we receive. Do not use this API in a production environment.

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

Signature:

round():FunctionExpression;

Returns:

FunctionExpression

A newExpression representing the rounded value.

Example

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

Expression.round()

This API is provided as a preview for developers and may change based on feedback that we receive. Do not use this API in a production environment.

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

Signature:

round(decimalPlaces:number):FunctionExpression;

Parameters

ParameterTypeDescription
decimalPlacesnumberA constant specifying the rounding precision in decimal places.

Returns:

FunctionExpression

A newExpression representing the rounded value.

Example

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

Expression.round()

This API is provided as a preview for developers and may change based on feedback that we receive. Do not use this API in a production environment.

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

Signature:

round(decimalPlaces:Expression):FunctionExpression;

Parameters

ParameterTypeDescription
decimalPlacesExpressionAn expression specifying the rounding precision in decimal places.

Returns:

FunctionExpression

A newExpression representing the rounded value.

Example

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

Expression.split()

This API is provided as a preview for developers and may change based on feedback that we receive. Do not use this API in a production environment.

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

Signature:

split(delimiter:string):FunctionExpression;

Parameters

ParameterTypeDescription
delimiterstring

Returns:

FunctionExpression

A newExpression representing the split function.

Example

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

Expression.split()

This API is provided as a preview for developers and may change based on feedback that we receive. Do not use this API in a production environment.

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

Signature:

split(delimiter:Expression):FunctionExpression;

Parameters

ParameterTypeDescription
delimiterExpression

Returns:

FunctionExpression

A newExpression representing the split function.

Example

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

Expression.sqrt()

This API is provided as a preview for developers and may change based on feedback that we receive. Do not use this API in a production environment.

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

Signature:

sqrt():FunctionExpression;

Returns:

FunctionExpression

A newExpression representing the square root of the numeric value.

Example

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

Expression.startsWith()

This API is provided as a preview for developers and may change based on feedback that we receive. Do not use this API in a production environment.

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

Signature:

startsWith(prefix:string):BooleanExpression;

Parameters

ParameterTypeDescription
prefixstringThe prefix to check for.

Returns:

BooleanExpression

A newExpression representing the 'starts with' comparison.

Example

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

Expression.startsWith()

This API is provided as a preview for developers and may change based on feedback that we receive. Do not use this API in a production environment.

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

Signature:

startsWith(prefix:Expression):BooleanExpression;

Parameters

ParameterTypeDescription
prefixExpressionThe prefix expression to check for.

Returns:

BooleanExpression

A newExpression representing the 'starts with' comparison.

Example

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

Expression.stringConcat()

This API is provided as a preview for developers and may change based on feedback that we receive. Do not use this API in a production environment.

Creates an expression that concatenates string expressions together.

Signature:

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.

Returns:

FunctionExpression

A newExpression representing the concatenated string.

Example

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

Expression.stringContains()

This API is provided as a preview for developers and may change based on feedback that we receive. Do not use this API in a production environment.

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

Signature:

stringContains(substring:string):BooleanExpression;

Parameters

ParameterTypeDescription
substringstringThe substring to search for.

Returns:

BooleanExpression

A newExpression representing the 'contains' comparison.

Example

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

Expression.stringContains()

This API is provided as a preview for developers and may change based on feedback that we receive. Do not use this API in a production environment.

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

Signature:

stringContains(expr:Expression):BooleanExpression;

Parameters

ParameterTypeDescription
exprExpressionThe expression representing the substring to search for.

Returns:

BooleanExpression

A newExpression representing the 'contains' comparison.

Example

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

Expression.stringReverse()

This API is provided as a preview for developers and may change based on feedback that we receive. Do not use this API in a production environment.

Creates an expression that reverses a string.

Signature:

stringReverse():FunctionExpression;

Returns:

FunctionExpression

A newExpression representing the reversed string.

Example

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

Expression.substring()

This API is provided as a preview for developers and may change based on feedback that we receive. Do not use this API in a production environment.

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

Signature:

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.

Returns:

FunctionExpression

Expression.substring()

This API is provided as a preview for developers and may change based on feedback that we receive. Do not use this API in a production environment.

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

Signature:

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.

Returns:

FunctionExpression

Expression.subtract()

This API is provided as a preview for developers and may change based on feedback that we receive. Do not use this API in a production environment.

Creates an expression that subtracts another expression from this expression.

Signature:

subtract(subtrahend:Expression):FunctionExpression;

Parameters

ParameterTypeDescription
subtrahendExpressionThe expression to subtract from this expression.

Returns:

FunctionExpression

A newExpression representing the subtraction operation.

Example

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

Expression.subtract()

This API is provided as a preview for developers and may change based on feedback that we receive. Do not use this API in a production environment.

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

Signature:

subtract(subtrahend:number):FunctionExpression;

Parameters

ParameterTypeDescription
subtrahendnumberThe constant value to subtract.

Returns:

FunctionExpression

A newExpression representing the subtraction operation.

Example

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

Expression.sum()

This API is provided as a preview for developers and may change based on feedback that we receive. Do not use this API in a production environment.

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

Signature:

sum():AggregateFunction;

Returns:

AggregateFunction

A newAggregateFunction representing the 'sum' aggregation.

Example

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

Expression.timestampAdd()

This API is provided as a preview for developers and may change based on feedback that we receive. Do not use this API in a production environment.

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

Signature:

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.

Returns:

FunctionExpression

A newExpression representing the resulting timestamp.

Example

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

Expression.timestampAdd()

This API is provided as a preview for developers and may change based on feedback that we receive. Do not use this API in a production environment.

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

Signature:

timestampAdd(unit:'microsecond'|'millisecond'|'second'|'minute'|'hour'|'day',amount:number):FunctionExpression;

Parameters

ParameterTypeDescription
unit'microsecond' | 'millisecond' | 'second' | 'minute' | 'hour' | 'day'The unit of time to add (e.g., "day", "hour").
amountnumberThe amount of time to add.

Returns:

FunctionExpression

A newExpression representing the resulting timestamp.

Example

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

Expression.timestampSubtract()

This API is provided as a preview for developers and may change based on feedback that we receive. Do not use this API in a production environment.

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

Signature:

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.

Returns:

FunctionExpression

A newExpression representing the resulting timestamp.

Example

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

Expression.timestampSubtract()

This API is provided as a preview for developers and may change based on feedback that we receive. Do not use this API in a production environment.

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

Signature:

timestampSubtract(unit:'microsecond'|'millisecond'|'second'|'minute'|'hour'|'day',amount:number):FunctionExpression;

Parameters

ParameterTypeDescription
unit'microsecond' | 'millisecond' | 'second' | 'minute' | 'hour' | 'day'The unit of time to subtract (e.g., "day", "hour").
amountnumberThe amount of time to subtract.

Returns:

FunctionExpression

A newExpression representing the resulting timestamp.

Example

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

Expression.timestampToUnixMicros()

This API is provided as a preview for developers and may change based on feedback that we receive. Do not use this API in a production environment.

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

Signature:

timestampToUnixMicros():FunctionExpression;

Returns:

FunctionExpression

A newExpression representing the number of microseconds since epoch.

Example

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

Expression.timestampToUnixMillis()

This API is provided as a preview for developers and may change based on feedback that we receive. Do not use this API in a production environment.

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

Signature:

timestampToUnixMillis():FunctionExpression;

Returns:

FunctionExpression

A newExpression representing the number of milliseconds since epoch.

Example

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

Expression.timestampToUnixSeconds()

This API is provided as a preview for developers and may change based on feedback that we receive. Do not use this API in a production environment.

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

Signature:

timestampToUnixSeconds():FunctionExpression;

Returns:

FunctionExpression

A newExpression representing the number of seconds since epoch.

Example

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

Expression.timestampTruncate()

This API is provided as a preview for developers and may change based on feedback that we receive. Do not use this API in a production environment.

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

Signature:

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

Returns:

FunctionExpression

A newExpression representing the truncated timestamp.

Example

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

Expression.timestampTruncate()

This API is provided as a preview for developers and may change based on feedback that we receive. Do not use this API in a production environment.

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

Signature:

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

Returns:

FunctionExpression

A newExpression representing the truncated timestamp.

Example

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

Expression.toLower()

This API is provided as a preview for developers and may change based on feedback that we receive. Do not use this API in a production environment.

Creates an expression that converts a string to lowercase.

Signature:

toLower():FunctionExpression;

Returns:

FunctionExpression

A newExpression representing the lowercase string.

Example

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

Expression.toUpper()

This API is provided as a preview for developers and may change based on feedback that we receive. Do not use this API in a production environment.

Creates an expression that converts a string to uppercase.

Signature:

toUpper():FunctionExpression;

Returns:

FunctionExpression

A newExpression representing the uppercase string.

Example

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

Expression.trim()

This API is provided as a preview for developers and may change based on feedback that we receive. Do not use this API in a production environment.

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

Signature:

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.

Returns:

FunctionExpression

A newExpression representing the trimmed string or byte array.

Example

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

Expression.type()

This API is provided as a preview for developers and may change based on feedback that we receive. Do not use this API in a production environment.

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

Signature:

type():FunctionExpression;

Returns:

FunctionExpression

A newExpression representing the data type.

Example

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

Expression.unixMicrosToTimestamp()

This API is provided as a preview for developers and may change based on feedback that we receive. Do not use this API in a production environment.

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.

Signature:

unixMicrosToTimestamp():FunctionExpression;

Returns:

FunctionExpression

A newExpression representing the timestamp.

Example

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

Expression.unixMillisToTimestamp()

This API is provided as a preview for developers and may change based on feedback that we receive. Do not use this API in a production environment.

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.

Signature:

unixMillisToTimestamp():FunctionExpression;

Returns:

FunctionExpression

A newExpression representing the timestamp.

Example

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

Expression.unixSecondsToTimestamp()

This API is provided as a preview for developers and may change based on feedback that we receive. Do not use this API in a production environment.

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.

Signature:

unixSecondsToTimestamp():FunctionExpression;

Returns:

FunctionExpression

A newExpression representing the timestamp.

Example

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

Expression.vectorLength()

This API is provided as a preview for developers and may change based on feedback that we receive. Do not use this API in a production environment.

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

Signature:

vectorLength():FunctionExpression;

Returns:

FunctionExpression

A newExpression representing the length of the vector.

Example

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

Except as otherwise noted, the content of this page is licensed under theCreative Commons Attribution 4.0 License, and code samples are licensed under theApache 2.0 License. For details, see theGoogle Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.

Last updated 2026-02-05 UTC.