Files
firebase-js-sdk/docs-devsite/firestore_pipelines.expression.md

5303 lines
155 KiB
Markdown

Project: /docs/reference/js/_project.yaml
Book: /docs/reference/_book.yaml
page_type: reference
{% comment %}
DO NOT EDIT THIS FILE!
This is generated by the JS SDK team, and any local changes will be
overwritten. Changes should be made in the source code at
https://github.com/firebase/firebase-js-sdk
{% endcomment %}
# Expression class
Represents an expression that can be evaluated to a value within the execution of a [Pipeline](./firestore_pipelines.pipeline.md#pipeline_class)<!-- -->.
Expressions are the building blocks for creating complex queries and transformations in Firestore pipelines. They can represent:
- \*\*Field references:\*\* Access values from document fields. - \*\*Literals:\*\* Represent constant values (strings, numbers, booleans). - \*\*Function calls:\*\* Apply functions to one or more expressions.
The `Expression` class provides a fluent API for building expressions. You can chain together method calls to create complex expressions.
<b>Signature:</b>
```typescript
export declare abstract class Expression
```
## Properties
| Property | Modifiers | Type | Description |
| --- | --- | --- | --- |
| [expressionType](./firestore_pipelines.expression.md#expressionexpressiontype) | | [ExpressionType](./firestore_pipelines.md#expressiontype) | |
## Methods
| Method | Modifiers | Description |
| --- | --- | --- |
| [abs()](./firestore_pipelines.expression.md#expressionabs) | | Creates an expression that computes the absolute value of a numeric value. |
| [add(second)](./firestore_pipelines.expression.md#expressionadd) | | Creates an expression that adds this expression to another expression. |
| [arrayAgg()](./firestore_pipelines.expression.md#expressionarrayagg) | | Creates an aggregation that collects all values of an expression across multiple stage inputs into an array. |
| [arrayAggDistinct()](./firestore_pipelines.expression.md#expressionarrayaggdistinct) | | Creates an aggregation that collects all distinct values of an expression across multiple stage inputs into an array. |
| [arrayConcat(secondArray, otherArrays)](./firestore_pipelines.expression.md#expressionarrayconcat) | | Creates an expression that concatenates an array expression with one or more other arrays. |
| [arrayContains(expression)](./firestore_pipelines.expression.md#expressionarraycontains) | | Creates an expression that checks if an array contains a specific element. |
| [arrayContains(value)](./firestore_pipelines.expression.md#expressionarraycontains) | | Creates an expression that checks if an array contains a specific value. |
| [arrayContainsAll(values)](./firestore_pipelines.expression.md#expressionarraycontainsall) | | Creates an expression that checks if an array contains all the specified elements. |
| [arrayContainsAll(arrayExpression)](./firestore_pipelines.expression.md#expressionarraycontainsall) | | Creates an expression that checks if an array contains all the specified elements. |
| [arrayContainsAny(values)](./firestore_pipelines.expression.md#expressionarraycontainsany) | | Creates an expression that checks if an array contains any of the specified elements. |
| [arrayContainsAny(arrayExpression)](./firestore_pipelines.expression.md#expressionarraycontainsany) | | Creates an expression that checks if an array contains any of the specified elements. |
| [arrayFilter(alias, filter)](./firestore_pipelines.expression.md#expressionarrayfilter) | | Filters the array using a provided alias and predicate expression. |
| [arrayFirst()](./firestore_pipelines.expression.md#expressionarrayfirst) | | Returns the first element of the array. |
| [arrayFirstN(n)](./firestore_pipelines.expression.md#expressionarrayfirstn) | | Returns the first <code>n</code> elements of the array. |
| [arrayFirstN(n)](./firestore_pipelines.expression.md#expressionarrayfirstn) | | Returns the first <code>n</code> elements of the array. |
| [arrayGet(offset)](./firestore_pipelines.expression.md#expressionarrayget) | | 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)](./firestore_pipelines.expression.md#expressionarrayget) | | Creates an expression that indexes into an array from the beginning or end and returns the element. If the offset exceeds the array length, an error is returned. A negative offset, starts from the end. |
| [arrayIndexOf(search)](./firestore_pipelines.expression.md#expressionarrayindexof) | | Returns the first index of the search value in the array, or -1 if not found. |
| [arrayIndexOf(search)](./firestore_pipelines.expression.md#expressionarrayindexof) | | Returns the first index of the search value in the array, or -1 if not found. |
| [arrayIndexOfAll(search)](./firestore_pipelines.expression.md#expressionarrayindexofall) | | Returns all indices of the search value in the array. |
| [arrayIndexOfAll(search)](./firestore_pipelines.expression.md#expressionarrayindexofall) | | Returns all indices of the search value in the array. |
| [arrayLast()](./firestore_pipelines.expression.md#expressionarraylast) | | Returns the last element of the array. |
| [arrayLastIndexOf(search)](./firestore_pipelines.expression.md#expressionarraylastindexof) | | Returns the last index of the search value in the array, or -1 if not found. |
| [arrayLastIndexOf(search)](./firestore_pipelines.expression.md#expressionarraylastindexof) | | Returns the last index of the search value in the array, or -1 if not found. |
| [arrayLastN(n)](./firestore_pipelines.expression.md#expressionarraylastn) | | Returns the last <code>n</code> elements of the array. |
| [arrayLastN(n)](./firestore_pipelines.expression.md#expressionarraylastn) | | Returns the last <code>n</code> elements of the array. |
| [arrayLength()](./firestore_pipelines.expression.md#expressionarraylength) | | Creates an expression that calculates the length of an array. |
| [arrayMaximum()](./firestore_pipelines.expression.md#expressionarraymaximum) | | Returns the maximum value in the array. |
| [arrayMaximumN(n)](./firestore_pipelines.expression.md#expressionarraymaximumn) | | Returns the largest <code>n</code> elements of the array.<!-- -->Note: Returns the n largest non-null elements in the array, in descending order. This does not use a stable sort, meaning the order of equivalent elements is undefined. |
| [arrayMaximumN(n)](./firestore_pipelines.expression.md#expressionarraymaximumn) | | Returns the largest <code>n</code> elements of the array.<!-- -->Note: Returns the n largest non-null elements in the array, in descending order. This does not use a stable sort, meaning the order of equivalent elements is undefined. |
| [arrayMinimum()](./firestore_pipelines.expression.md#expressionarrayminimum) | | Returns the minimum value in the array. |
| [arrayMinimumN(n)](./firestore_pipelines.expression.md#expressionarrayminimumn) | | Returns the smallest <code>n</code> elements of the array.<!-- -->Note: Returns the n smallest non-null elements in the array, in ascending order. This does not use a stable sort, meaning the order of equivalent elements is undefined. |
| [arrayMinimumN(n)](./firestore_pipelines.expression.md#expressionarrayminimumn) | | Returns the smallest <code>n</code> elements of the array.<!-- -->Note: Returns the n smallest non-null elements in the array, in ascending order. This does not use a stable sort, meaning the order of equivalent elements is undefined. |
| [arrayReverse()](./firestore_pipelines.expression.md#expressionarrayreverse) | | Creates an expression that reverses an array. |
| [arraySlice(offset, length)](./firestore_pipelines.expression.md#expressionarrayslice) | | Returns a subset of the array. |
| [arraySum()](./firestore_pipelines.expression.md#expressionarraysum) | | Creates an expression that computes the sum of the elements in an array. |
| [arrayTransform(elementAlias, transform)](./firestore_pipelines.expression.md#expressionarraytransform) | | Creates an expression that applies a provided transformation to each element in an array. |
| [arrayTransformWithIndex(elementAlias, indexAlias, transform)](./firestore_pipelines.expression.md#expressionarraytransformwithindex) | | Creates an expression that applies a provided transformation to each element in an array, providing the element's index to the transformation expression. |
| [as(name)](./firestore_pipelines.expression.md#expressionas) | | 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()](./firestore_pipelines.expression.md#expressionasboolean) | | Wraps the expression in a \[BooleanExpression\]. |
| [ascending()](./firestore_pipelines.expression.md#expressionascending) | | Creates an [Ordering](./firestore_pipelines.ordering.md#ordering_class) that sorts documents in ascending order based on this expression. |
| [average()](./firestore_pipelines.expression.md#expressionaverage) | | Creates an aggregation that calculates the average (mean) of a numeric field across multiple stage inputs. |
| [byteLength()](./firestore_pipelines.expression.md#expressionbytelength) | | Creates an expression that calculates the length of this string expression in bytes. |
| [ceil()](./firestore_pipelines.expression.md#expressionceil) | | Creates an expression that computes the ceiling of a numeric value. |
| [charLength()](./firestore_pipelines.expression.md#expressioncharlength) | | Creates an expression that calculates the character length of a string in UTF-8. |
| [coalesce(replacement, others)](./firestore_pipelines.expression.md#expressioncoalesce) | | Creates an expression that returns the first non-null, non-absent argument, without evaluating the rest of the arguments. When all arguments are null or absent, returns the last argument. |
| [collectionId()](./firestore_pipelines.expression.md#expressioncollectionid) | | Creates an expression that returns the collection ID from a path. |
| [concat(second, others)](./firestore_pipelines.expression.md#expressionconcat) | | Creates an expression that concatenates expression results together. |
| [cosineDistance(vectorExpression)](./firestore_pipelines.expression.md#expressioncosinedistance) | | Calculates the cosine distance between two vectors. |
| [cosineDistance(vector)](./firestore_pipelines.expression.md#expressioncosinedistance) | | Calculates the Cosine distance between two vectors. |
| [count()](./firestore_pipelines.expression.md#expressioncount) | | Creates an aggregation that counts the number of stage inputs with valid evaluations of the expression or field. |
| [countDistinct()](./firestore_pipelines.expression.md#expressioncountdistinct) | | Creates an aggregation that counts the number of distinct values of the expression or field. |
| [descending()](./firestore_pipelines.expression.md#expressiondescending) | | Creates an [Ordering](./firestore_pipelines.ordering.md#ordering_class) that sorts documents in descending order based on this expression. |
| [divide(divisor)](./firestore_pipelines.expression.md#expressiondivide) | | Creates an expression that divides this expression by another expression. |
| [divide(divisor)](./firestore_pipelines.expression.md#expressiondivide) | | Creates an expression that divides this expression by a constant value. |
| [documentId()](./firestore_pipelines.expression.md#expressiondocumentid) | | Creates an expression that returns the document ID from a path. |
| [dotProduct(vectorExpression)](./firestore_pipelines.expression.md#expressiondotproduct) | | Calculates the dot product between two vectors. |
| [dotProduct(vector)](./firestore_pipelines.expression.md#expressiondotproduct) | | Calculates the dot product between two vectors. |
| [endsWith(suffix)](./firestore_pipelines.expression.md#expressionendswith) | | Creates an expression that checks if a string ends with a given postfix. |
| [endsWith(suffix)](./firestore_pipelines.expression.md#expressionendswith) | | Creates an expression that checks if a string ends with a given postfix (represented as an expression). |
| [equal(expression)](./firestore_pipelines.expression.md#expressionequal) | | Creates an expression that checks if this expression is equal to another expression. |
| [equal(value)](./firestore_pipelines.expression.md#expressionequal) | | Creates an expression that checks if this expression is equal to a constant value. |
| [equalAny(values)](./firestore_pipelines.expression.md#expressionequalany) | | Creates an expression that checks if this expression is equal to any of the provided values or expressions. |
| [equalAny(arrayExpression)](./firestore_pipelines.expression.md#expressionequalany) | | Creates an expression that checks if this expression is equal to any of the provided values or expressions. |
| [euclideanDistance(vectorExpression)](./firestore_pipelines.expression.md#expressioneuclideandistance) | | Calculates the Euclidean distance between two vectors. |
| [euclideanDistance(vector)](./firestore_pipelines.expression.md#expressioneuclideandistance) | | Calculates the Euclidean distance between two vectors. |
| [exists()](./firestore_pipelines.expression.md#expressionexists) | | Creates an expression that checks if a field exists in the document. |
| [exp()](./firestore_pipelines.expression.md#expressionexp) | | Creates an expression that computes e to the power of this expression. |
| [first()](./firestore_pipelines.expression.md#expressionfirst) | | Creates an aggregation that finds the first value of an expression across multiple stage inputs. |
| [floor()](./firestore_pipelines.expression.md#expressionfloor) | | Creates an expression that computes the floor of a numeric value. |
| [getField(key)](./firestore_pipelines.expression.md#expressiongetfield) | | Creates an expression that returns the value of a field from the document that results from the evaluation of this expression. |
| [greaterThan(expression)](./firestore_pipelines.expression.md#expressiongreaterthan) | | Creates an expression that checks if this expression is greater than another expression. |
| [greaterThan(value)](./firestore_pipelines.expression.md#expressiongreaterthan) | | Creates an expression that checks if this expression is greater than a constant value. |
| [greaterThanOrEqual(expression)](./firestore_pipelines.expression.md#expressiongreaterthanorequal) | | Creates an expression that checks if this expression is greater than or equal to another expression. |
| [greaterThanOrEqual(value)](./firestore_pipelines.expression.md#expressiongreaterthanorequal) | | Creates an expression that checks if this expression is greater than or equal to a constant value. |
| [ifAbsent(elseValue)](./firestore_pipelines.expression.md#expressionifabsent) | | Creates an expression that returns the <code>elseValue</code> argument if this expression results in an absent value, else return the result of this expression evaluation. |
| [ifAbsent(elseExpression)](./firestore_pipelines.expression.md#expressionifabsent) | | Creates an expression that returns the <code>elseValue</code> argument if this expression results in an absent value, else return the result of this expression evaluation. |
| [ifError(catchExpr)](./firestore_pipelines.expression.md#expressioniferror) | | Creates an expression that returns the result of the <code>catchExpr</code> argument if there is an error, else return the result of this expression. |
| [ifError(catchValue)](./firestore_pipelines.expression.md#expressioniferror) | | Creates an expression that returns the <code>catch</code> argument if there is an error, else return the result of this expression. |
| [ifNull(elseExpression)](./firestore_pipelines.expression.md#expressionifnull) | | Creates an expression that returns the <code>elseValue</code> argument if this expression evaluates to null, else return the result of this expression evaluation. |
| [ifNull(elseValue)](./firestore_pipelines.expression.md#expressionifnull) | | Creates an expression that returns the <code>elseValue</code> argument if this expression evaluates to null, else return the result of this expression evaluation. |
| [isAbsent()](./firestore_pipelines.expression.md#expressionisabsent) | | Creates an expression that returns <code>true</code> if the result of this expression is absent. Otherwise, returns <code>false</code> even if the value is <code>null</code>. |
| [isError()](./firestore_pipelines.expression.md#expressioniserror) | | Creates an expression that checks if a given expression produces an error. |
| [isType(type)](./firestore_pipelines.expression.md#expressionistype) | | Creates an expression that checks if the result of this expression is of the given type. |
| [join(delimiterExpression)](./firestore_pipelines.expression.md#expressionjoin) | | Creates an expression that joins the elements of an array into a string. |
| [join(delimiter)](./firestore_pipelines.expression.md#expressionjoin) | | Creates an expression that joins the elements of an array field into a string. |
| [last()](./firestore_pipelines.expression.md#expressionlast) | | Creates an aggregation that finds the last value of an expression across multiple stage inputs. |
| [length()](./firestore_pipelines.expression.md#expressionlength) | | Creates an expression that calculates the length of a string, array, map, vector, or bytes. |
| [lessThan(experession)](./firestore_pipelines.expression.md#expressionlessthan) | | Creates an expression that checks if this expression is less than another expression. |
| [lessThan(value)](./firestore_pipelines.expression.md#expressionlessthan) | | Creates an expression that checks if this expression is less than a constant value. |
| [lessThanOrEqual(expression)](./firestore_pipelines.expression.md#expressionlessthanorequal) | | Creates an expression that checks if this expression is less than or equal to another expression. |
| [lessThanOrEqual(value)](./firestore_pipelines.expression.md#expressionlessthanorequal) | | Creates an expression that checks if this expression is less than or equal to a constant value. |
| [like(pattern)](./firestore_pipelines.expression.md#expressionlike) | | Creates an expression that performs a case-sensitive string comparison. |
| [like(pattern)](./firestore_pipelines.expression.md#expressionlike) | | Creates an expression that performs a case-sensitive string comparison. |
| [ln()](./firestore_pipelines.expression.md#expressionln) | | Creates an expression that computes the natural logarithm of a numeric value. |
| [log10()](./firestore_pipelines.expression.md#expressionlog10) | | Creates an expression that computes the base-10 logarithm of a numeric value. |
| [logicalMaximum(second, others)](./firestore_pipelines.expression.md#expressionlogicalmaximum) | | Creates an expression that returns the larger value between this expression and another expression, based on Firestore's value type ordering. |
| [logicalMinimum(second, others)](./firestore_pipelines.expression.md#expressionlogicalminimum) | | Creates an expression that returns the smaller value between this expression and another expression, based on Firestore's value type ordering. |
| [ltrim(valueToTrim)](./firestore_pipelines.expression.md#expressionltrim) | | Trims whitespace or a specified set of characters/bytes from the beginning of a string or byte array. |
| [mapEntries()](./firestore_pipelines.expression.md#expressionmapentries) | | Creates an expression that returns the entries of a map as an array of maps, where each map contains a <code>&quot;k&quot;</code> property for the key and a <code>&quot;v&quot;</code> property for the value. For example: <code>[{ k: &quot;key1&quot;, v: &quot;value1&quot; }, ...]</code>. |
| [mapGet(subfield)](./firestore_pipelines.expression.md#expressionmapget) | | Accesses a value from a map (object) field using the provided key. |
| [mapKeys()](./firestore_pipelines.expression.md#expressionmapkeys) | | Creates an expression that returns the keys of a map. |
| [mapMerge(secondMap, otherMaps)](./firestore_pipelines.expression.md#expressionmapmerge) | | Creates an expression that merges multiple map values. |
| [mapRemove(key)](./firestore_pipelines.expression.md#expressionmapremove) | | Creates an expression that removes a key from the map produced by evaluating this expression. |
| [mapRemove(keyExpr)](./firestore_pipelines.expression.md#expressionmapremove) | | Creates an expression that removes a key from the map produced by evaluating this expression. |
| [mapSet(key, value, moreKeyValues)](./firestore_pipelines.expression.md#expressionmapset) | | Creates an expression that returns a new map with the specified entries added or updated. |
| [mapValues()](./firestore_pipelines.expression.md#expressionmapvalues) | | Creates an expression that returns the values of a map. |
| [maximum()](./firestore_pipelines.expression.md#expressionmaximum) | | Creates an aggregation that finds the maximum value of a field across multiple stage inputs. |
| [minimum()](./firestore_pipelines.expression.md#expressionminimum) | | Creates an aggregation that finds the minimum value of a field across multiple stage inputs. |
| [mod(expression)](./firestore_pipelines.expression.md#expressionmod) | | Creates an expression that calculates the modulo (remainder) of dividing this expression by another expression. |
| [mod(value)](./firestore_pipelines.expression.md#expressionmod) | | Creates an expression that calculates the modulo (remainder) of dividing this expression by a constant value. |
| [multiply(second)](./firestore_pipelines.expression.md#expressionmultiply) | | Creates an expression that multiplies this expression by another expression. |
| [notEqual(expression)](./firestore_pipelines.expression.md#expressionnotequal) | | Creates an expression that checks if this expression is not equal to another expression. |
| [notEqual(value)](./firestore_pipelines.expression.md#expressionnotequal) | | Creates an expression that checks if this expression is not equal to a constant value. |
| [notEqualAny(values)](./firestore_pipelines.expression.md#expressionnotequalany) | | Creates an expression that checks if this expression is not equal to any of the provided values or expressions. |
| [notEqualAny(arrayExpression)](./firestore_pipelines.expression.md#expressionnotequalany) | | Creates an expression that checks if this expression is not equal to any of the values in the evaluated expression. |
| [parent()](./firestore_pipelines.expression.md#expressionparent) | | Creates an expression that returns the parent document reference of a document reference. |
| [pow(exponent)](./firestore_pipelines.expression.md#expressionpow) | | Creates an expression that returns the value of this expression raised to the power of another expression. |
| [pow(exponent)](./firestore_pipelines.expression.md#expressionpow) | | Creates an expression that returns the value of this expression raised to the power of a constant value. |
| [regexContains(pattern)](./firestore_pipelines.expression.md#expressionregexcontains) | | Creates an expression that checks if a string contains a specified regular expression as a substring. |
| [regexContains(pattern)](./firestore_pipelines.expression.md#expressionregexcontains) | | Creates an expression that checks if a string contains a specified regular expression as a substring. |
| [regexFind(pattern)](./firestore_pipelines.expression.md#expressionregexfind) | | Creates an expression that returns the first substring of a string expression that matches a specified regular expression.<!-- -->This expression uses the [RE2](https://github.com/google/re2/wiki/Syntax) regular expression syntax. |
| [regexFind(pattern)](./firestore_pipelines.expression.md#expressionregexfind) | | Creates an expression that returns the first substring of a string expression that matches a specified regular expression.<!-- -->This expression uses the [RE2](https://github.com/google/re2/wiki/Syntax) regular expression syntax. |
| [regexFindAll(pattern)](./firestore_pipelines.expression.md#expressionregexfindall) | | Creates an expression that evaluates to a list of all substrings in this string expression that match a specified regular expression.<!-- -->This expression uses the [RE2](https://github.com/google/re2/wiki/Syntax) regular expression syntax. |
| [regexFindAll(pattern)](./firestore_pipelines.expression.md#expressionregexfindall) | | Creates an expression that evaluates to a list of all substrings in this string expression that match a specified regular expression.<!-- -->This expression uses the [RE2](https://github.com/google/re2/wiki/Syntax) regular expression syntax. |
| [regexMatch(pattern)](./firestore_pipelines.expression.md#expressionregexmatch) | | Creates an expression that checks if a string matches a specified regular expression. |
| [regexMatch(pattern)](./firestore_pipelines.expression.md#expressionregexmatch) | | Creates an expression that checks if a string matches a specified regular expression. |
| [reverse()](./firestore_pipelines.expression.md#expressionreverse) | | Creates an expression that reverses this string expression. |
| [round()](./firestore_pipelines.expression.md#expressionround) | | Creates an expression that rounds a numeric value to the nearest whole number. |
| [round(decimalPlaces)](./firestore_pipelines.expression.md#expressionround) | | Creates an expression that rounds a numeric value to the specified number of decimal places. |
| [round(decimalPlaces)](./firestore_pipelines.expression.md#expressionround) | | Creates an expression that rounds a numeric value to the specified number of decimal places. |
| [rtrim(valueToTrim)](./firestore_pipelines.expression.md#expressionrtrim) | | Trims whitespace or a specified set of characters/bytes from the end of a string or byte array. |
| [split(delimiter)](./firestore_pipelines.expression.md#expressionsplit) | | Creates an expression that splits the result of this expression into an array of substrings based on the provided delimiter. |
| [split(delimiter)](./firestore_pipelines.expression.md#expressionsplit) | | Creates an expression that splits the result of this expression into an array of substrings based on the provided delimiter. |
| [sqrt()](./firestore_pipelines.expression.md#expressionsqrt) | | Creates an expression that computes the square root of a numeric value. |
| [startsWith(prefix)](./firestore_pipelines.expression.md#expressionstartswith) | | Creates an expression that checks if a string starts with a given prefix. |
| [startsWith(prefix)](./firestore_pipelines.expression.md#expressionstartswith) | | Creates an expression that checks if a string starts with a given prefix (represented as an expression). |
| [stringConcat(secondString, otherStrings)](./firestore_pipelines.expression.md#expressionstringconcat) | | Creates an expression that concatenates string expressions together. |
| [stringContains(substring)](./firestore_pipelines.expression.md#expressionstringcontains) | | Creates an expression that checks if a string contains a specified substring. |
| [stringContains(expr)](./firestore_pipelines.expression.md#expressionstringcontains) | | Creates an expression that checks if a string contains the string represented by another expression. |
| [stringIndexOf(search)](./firestore_pipelines.expression.md#expressionstringindexof) | | Creates an expression that finds the index of the first occurrence of a substring or byte sequence. |
| [stringRepeat(repetitions)](./firestore_pipelines.expression.md#expressionstringrepeat) | | Creates an expression that repeats a string or byte array a specified number of times. |
| [stringReplaceAll(find, replacement)](./firestore_pipelines.expression.md#expressionstringreplaceall) | | Creates an expression that replaces all occurrences of a substring or byte sequence with a replacement. |
| [stringReplaceOne(find, replacement)](./firestore_pipelines.expression.md#expressionstringreplaceone) | | Creates an expression that replaces the first occurrence of a substring or byte sequence with a replacement. |
| [stringReverse()](./firestore_pipelines.expression.md#expressionstringreverse) | | Creates an expression that reverses a string. |
| [substring(position, length)](./firestore_pipelines.expression.md#expressionsubstring) | | Creates an expression that returns a substring of the results of this expression. |
| [substring(position, length)](./firestore_pipelines.expression.md#expressionsubstring) | | Creates an expression that returns a substring of the results of this expression. |
| [subtract(subtrahend)](./firestore_pipelines.expression.md#expressionsubtract) | | Creates an expression that subtracts another expression from this expression. |
| [subtract(subtrahend)](./firestore_pipelines.expression.md#expressionsubtract) | | Creates an expression that subtracts a constant value from this expression. |
| [sum()](./firestore_pipelines.expression.md#expressionsum) | | Creates an aggregation that calculates the sum of a numeric field across multiple stage inputs. |
| [timestampAdd(unit, amount)](./firestore_pipelines.expression.md#expressiontimestampadd) | | Creates an expression that adds a specified amount of time to this timestamp expression. |
| [timestampAdd(unit, amount)](./firestore_pipelines.expression.md#expressiontimestampadd) | | Creates an expression that adds a specified amount of time to this timestamp expression. |
| [timestampDiff(start, unit)](./firestore_pipelines.expression.md#expressiontimestampdiff) | | Creates an expression that calculates the difference between this timestamp and another timestamp. |
| [timestampDiff(start, unit)](./firestore_pipelines.expression.md#expressiontimestampdiff) | | Creates an expression that calculates the difference between this timestamp and another timestamp. |
| [timestampExtract(part, timezone)](./firestore_pipelines.expression.md#expressiontimestampextract) | | Creates an expression that extracts a specified part from this timestamp expression. |
| [timestampExtract(part, timezone)](./firestore_pipelines.expression.md#expressiontimestampextract) | | Creates an expression that extracts a specified part from this timestamp expression. |
| [timestampSubtract(unit, amount)](./firestore_pipelines.expression.md#expressiontimestampsubtract) | | Creates an expression that subtracts a specified amount of time from this timestamp expression. |
| [timestampSubtract(unit, amount)](./firestore_pipelines.expression.md#expressiontimestampsubtract) | | Creates an expression that subtracts a specified amount of time from this timestamp expression. |
| [timestampToUnixMicros()](./firestore_pipelines.expression.md#expressiontimestamptounixmicros) | | 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()](./firestore_pipelines.expression.md#expressiontimestamptounixmillis) | | 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()](./firestore_pipelines.expression.md#expressiontimestamptounixseconds) | | 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)](./firestore_pipelines.expression.md#expressiontimestamptruncate) | | Creates an expression that truncates a timestamp to a specified granularity. |
| [timestampTruncate(granularity, timezone)](./firestore_pipelines.expression.md#expressiontimestamptruncate) | | Creates an expression that truncates a timestamp to a specified granularity. |
| [toLower()](./firestore_pipelines.expression.md#expressiontolower) | | Creates an expression that converts a string to lowercase. |
| [toUpper()](./firestore_pipelines.expression.md#expressiontoupper) | | Creates an expression that converts a string to uppercase. |
| [trim(valueToTrim)](./firestore_pipelines.expression.md#expressiontrim) | | Creates an expression that removes leading and trailing characters from a string or byte array. |
| [trunc()](./firestore_pipelines.expression.md#expressiontrunc) | | Creates an expression that truncates the numeric value to an integer. |
| [trunc(decimalPlaces)](./firestore_pipelines.expression.md#expressiontrunc) | | Creates an expression that truncates a numeric value to the specified number of decimal places. |
| [trunc(decimalPlaces)](./firestore_pipelines.expression.md#expressiontrunc) | | Creates an expression that truncates a numeric value to the specified number of decimal places. |
| [type()](./firestore_pipelines.expression.md#expressiontype) | | Creates an expression that returns the data type of this expression's result, as a string. |
| [unixMicrosToTimestamp()](./firestore_pipelines.expression.md#expressionunixmicrostotimestamp) | | 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()](./firestore_pipelines.expression.md#expressionunixmillistotimestamp) | | 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()](./firestore_pipelines.expression.md#expressionunixsecondstotimestamp) | | 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()](./firestore_pipelines.expression.md#expressionvectorlength) | | Creates an expression that calculates the length (number of dimensions) of this Firestore Vector expression. |
## Expression.expressionType
<b>Signature:</b>
```typescript
abstract readonly expressionType: ExpressionType;
```
## Expression.abs()
Creates an expression that computes the absolute value of a numeric value.
<b>Signature:</b>
```typescript
abs(): FunctionExpression;
```
<b>Returns:</b>
[FunctionExpression](./firestore_pipelines.functionexpression.md#functionexpression_class)
A new [Expression](./firestore_pipelines.expression.md#expression_class) representing the absolute value of the numeric value.
### Example
```typescript
// Compute the absolute value of the 'price' field.
field("price").abs();
```
## Expression.add()
Creates an expression that adds this expression to another expression.
<b>Signature:</b>
```typescript
add(second: Expression | unknown): FunctionExpression;
```
#### Parameters
| Parameter | Type | Description |
| --- | --- | --- |
| second | [Expression](./firestore_pipelines.expression.md#expression_class) \| unknown | The expression or literal to add to this expression. |
<b>Returns:</b>
[FunctionExpression](./firestore_pipelines.functionexpression.md#functionexpression_class)
A new `Expression` representing the addition operation.
### Example
```typescript
// Add the value of the 'quantity' field and the 'reserve' field.
field("quantity").add(field("reserve"));
```
## Expression.arrayAgg()
Creates an aggregation that collects all values of an expression across multiple stage inputs into an array.
If the expression resolves to an absent value, it is converted to `null`<!-- -->. The order of elements in the output array is not stable and shouldn't be relied upon.
<b>Signature:</b>
```typescript
arrayAgg(): AggregateFunction;
```
<b>Returns:</b>
[AggregateFunction](./firestore_pipelines.aggregatefunction.md#aggregatefunction_class)
A new `AggregateFunction` representing the 'array\_agg' aggregation.
### Example
```typescript
// Collect all tags from books into an array
field("tags").arrayAgg().as("allTags");
```
## Expression.arrayAggDistinct()
Creates an aggregation that collects all distinct values of an expression across multiple stage inputs into an array.
If the expression resolves to an absent value, it is converted to `null`<!-- -->. The order of elements in the output array is not stable and shouldn't be relied upon.
<b>Signature:</b>
```typescript
arrayAggDistinct(): AggregateFunction;
```
<b>Returns:</b>
[AggregateFunction](./firestore_pipelines.aggregatefunction.md#aggregatefunction_class)
A new `AggregateFunction` representing the 'array\_agg\_distinct' aggregation.
### Example
```typescript
// Collect all distinct tags from books into an array
field("tags").arrayAggDistinct().as("allDistinctTags");
```
## Expression.arrayConcat()
Creates an expression that concatenates an array expression with one or more other arrays.
<b>Signature:</b>
```typescript
arrayConcat(secondArray: Expression | unknown[], ...otherArrays: Array<Expression | unknown[]>): FunctionExpression;
```
#### Parameters
| Parameter | Type | Description |
| --- | --- | --- |
| secondArray | [Expression](./firestore_pipelines.expression.md#expression_class) \| unknown\[\] | Second array expression or array literal to concatenate. |
| otherArrays | Array&lt;[Expression](./firestore_pipelines.expression.md#expression_class) \| unknown\[\]&gt; | Optional additional array expressions or array literals to concatenate. |
<b>Returns:</b>
[FunctionExpression](./firestore_pipelines.functionexpression.md#functionexpression_class)
A new `Expression` representing the concatenated array.
### Example
```typescript
// Combine the 'items' array with another array field.
field("items").arrayConcat(field("otherItems"));
```
## Expression.arrayContains()
Creates an expression that checks if an array contains a specific element.
<b>Signature:</b>
```typescript
arrayContains(expression: Expression): BooleanExpression;
```
#### Parameters
| Parameter | Type | Description |
| --- | --- | --- |
| expression | [Expression](./firestore_pipelines.expression.md#expression_class) | The element to search for in the array. |
<b>Returns:</b>
[BooleanExpression](./firestore_pipelines.booleanexpression.md#booleanexpression_class)
A new `Expression` representing the 'array\_contains' comparison.
### Example
```typescript
// Check if the 'sizes' array contains the value from the 'selectedSize' field
field("sizes").arrayContains(field("selectedSize"));
```
## Expression.arrayContains()
Creates an expression that checks if an array contains a specific value.
<b>Signature:</b>
```typescript
arrayContains(value: unknown): BooleanExpression;
```
#### Parameters
| Parameter | Type | Description |
| --- | --- | --- |
| value | unknown | The element to search for in the array. |
<b>Returns:</b>
[BooleanExpression](./firestore_pipelines.booleanexpression.md#booleanexpression_class)
A new `Expression` representing the 'array\_contains' comparison.
### Example
```typescript
// Check if the 'colors' array contains "red"
field("colors").arrayContains("red");
```
## Expression.arrayContainsAll()
Creates an expression that checks if an array contains all the specified elements.
<b>Signature:</b>
```typescript
arrayContainsAll(values: Array<Expression | unknown>): BooleanExpression;
```
#### Parameters
| Parameter | Type | Description |
| --- | --- | --- |
| values | Array&lt;[Expression](./firestore_pipelines.expression.md#expression_class) \| unknown&gt; | The elements to check for in the array. |
<b>Returns:</b>
[BooleanExpression](./firestore_pipelines.booleanexpression.md#booleanexpression_class)
A new `Expression` representing the 'array\_contains\_all' comparison.
### Example
```typescript
// Check if the 'tags' array contains both the value in field "tag1" and the literal value "tag2"
field("tags").arrayContainsAll([field("tag1"), "tag2"]);
```
## Expression.arrayContainsAll()
Creates an expression that checks if an array contains all the specified elements.
<b>Signature:</b>
```typescript
arrayContainsAll(arrayExpression: Expression): BooleanExpression;
```
#### Parameters
| Parameter | Type | Description |
| --- | --- | --- |
| arrayExpression | [Expression](./firestore_pipelines.expression.md#expression_class) | The elements to check for in the array. |
<b>Returns:</b>
[BooleanExpression](./firestore_pipelines.booleanexpression.md#booleanexpression_class)
A new `Expression` representing the 'array\_contains\_all' comparison.
### Example
```typescript
// Check if the 'tags' array contains both of the values from field "tag1" and the literal value "tag2"
field("tags").arrayContainsAll(array([field("tag1"), "tag2"]));
```
## Expression.arrayContainsAny()
Creates an expression that checks if an array contains any of the specified elements.
<b>Signature:</b>
```typescript
arrayContainsAny(values: Array<Expression | unknown>): BooleanExpression;
```
#### Parameters
| Parameter | Type | Description |
| --- | --- | --- |
| values | Array&lt;[Expression](./firestore_pipelines.expression.md#expression_class) \| unknown&gt; | The elements to check for in the array. |
<b>Returns:</b>
[BooleanExpression](./firestore_pipelines.booleanexpression.md#booleanexpression_class)
A new `Expression` representing the 'array\_contains\_any' comparison.
### Example
```typescript
// Check if the 'categories' array contains either values from field "cate1" or "cate2"
field("categories").arrayContainsAny([field("cate1"), field("cate2")]);
```
## Expression.arrayContainsAny()
Creates an expression that checks if an array contains any of the specified elements.
<b>Signature:</b>
```typescript
arrayContainsAny(arrayExpression: Expression): BooleanExpression;
```
#### Parameters
| Parameter | Type | Description |
| --- | --- | --- |
| arrayExpression | [Expression](./firestore_pipelines.expression.md#expression_class) | The elements to check for in the array. |
<b>Returns:</b>
[BooleanExpression](./firestore_pipelines.booleanexpression.md#booleanexpression_class)
A new `Expression` representing the 'array\_contains\_any' comparison.
### Example
```typescript
// Check if the 'groups' array contains either the value from the 'userGroup' field
// or the value "guest"
field("groups").arrayContainsAny(array([field("userGroup"), "guest"]));
```
## Expression.arrayFilter()
Filters the array using a provided alias and predicate expression.
<b>Signature:</b>
```typescript
arrayFilter(alias: string, filter: BooleanExpression): FunctionExpression;
```
#### Parameters
| Parameter | Type | Description |
| --- | --- | --- |
| alias | string | The variable name to use for each element. |
| filter | [BooleanExpression](./firestore_pipelines.booleanexpression.md#booleanexpression_class) | The predicate boolean expression to filter by. |
<b>Returns:</b>
[FunctionExpression](./firestore_pipelines.functionexpression.md#functionexpression_class)
A new `Expression` representing the filtered array.
### Example
```typescript
// Filter the 'items' array to only include those where the 'price' is greater than 10
field("items").arrayFilter('item', greaterThan(variable('item.price'), 10));
```
## Expression.arrayFirst()
Returns the first element of the array.
<b>Signature:</b>
```typescript
arrayFirst(): FunctionExpression;
```
<b>Returns:</b>
[FunctionExpression](./firestore_pipelines.functionexpression.md#functionexpression_class)
A new `Expression` representing the first element.
### Example
```typescript
// Get the first element of the 'myArray' field.
field("myArray").arrayFirst();
```
## Expression.arrayFirstN()
Returns the first `n` elements of the array.
<b>Signature:</b>
```typescript
arrayFirstN(n: number): FunctionExpression;
```
#### Parameters
| Parameter | Type | Description |
| --- | --- | --- |
| n | number | The number of elements to return. |
<b>Returns:</b>
[FunctionExpression](./firestore_pipelines.functionexpression.md#functionexpression_class)
A new `Expression` representing the first `n` elements.
### Example
```typescript
// Get the first 3 elements of the 'myArray' field.
field("myArray").arrayFirstN(3);
```
## Expression.arrayFirstN()
Returns the first `n` elements of the array.
<b>Signature:</b>
```typescript
arrayFirstN(n: Expression): FunctionExpression;
```
#### Parameters
| Parameter | Type | Description |
| --- | --- | --- |
| n | [Expression](./firestore_pipelines.expression.md#expression_class) | An expression evaluating to the number of elements to return. |
<b>Returns:</b>
[FunctionExpression](./firestore_pipelines.functionexpression.md#functionexpression_class)
A new `Expression` representing the first `n` elements.
### Example
```typescript
// Get the first n elements of the 'myArray' field.
field("myArray").arrayFirstN(field("count"));
```
## Expression.arrayGet()
Creates an expression that indexes into an array from the beginning or end and returns the element. If the offset exceeds the array length, an error is returned. A negative offset, starts from the end.
<b>Signature:</b>
```typescript
arrayGet(offset: number): FunctionExpression;
```
#### Parameters
| Parameter | Type | Description |
| --- | --- | --- |
| offset | number | The index of the element to return. |
<b>Returns:</b>
[FunctionExpression](./firestore_pipelines.functionexpression.md#functionexpression_class)
A new `Expression` representing the 'arrayGet' operation.
### Example
```typescript
// Return the value in the 'tags' field array at index `1`.
field('tags').arrayGet(1);
```
## Expression.arrayGet()
Creates an expression that indexes into an array from the beginning or end and returns the element. If the offset exceeds the array length, an error is returned. A negative offset, starts from the end.
<b>Signature:</b>
```typescript
arrayGet(offsetExpr: Expression): FunctionExpression;
```
#### Parameters
| Parameter | Type | Description |
| --- | --- | --- |
| offsetExpr | [Expression](./firestore_pipelines.expression.md#expression_class) | An <code>Expression</code> evaluating to the index of the element to return. |
<b>Returns:</b>
[FunctionExpression](./firestore_pipelines.functionexpression.md#functionexpression_class)
A new `Expression` representing the 'arrayGet' operation.
### Example
```typescript
// Return the value in the tags field array at index specified by field
// 'favoriteTag'.
field('tags').arrayGet(field('favoriteTag'));
```
## Expression.arrayIndexOf()
Returns the first index of the search value in the array, or -1 if not found.
<b>Signature:</b>
```typescript
arrayIndexOf(search: unknown): FunctionExpression;
```
#### Parameters
| Parameter | Type | Description |
| --- | --- | --- |
| search | unknown | The value to search for. |
<b>Returns:</b>
[FunctionExpression](./firestore_pipelines.functionexpression.md#functionexpression_class)
A new `Expression` representing the index.
### Example
```typescript
// Get the first index of the value 3 in the 'myArray' field.
field("myArray").arrayIndexOf(3);
```
## Expression.arrayIndexOf()
Returns the first index of the search value in the array, or -1 if not found.
<b>Signature:</b>
```typescript
arrayIndexOf(search: Expression): FunctionExpression;
```
#### Parameters
| Parameter | Type | Description |
| --- | --- | --- |
| search | [Expression](./firestore_pipelines.expression.md#expression_class) | An expression evaluating to the value to search for. |
<b>Returns:</b>
[FunctionExpression](./firestore_pipelines.functionexpression.md#functionexpression_class)
A new `Expression` representing the index.
### Example
```typescript
// Get the first index of the value in 'searchVal' field in the 'myArray' field.
field("myArray").arrayIndexOf(field("searchVal"));
```
## Expression.arrayIndexOfAll()
Returns all indices of the search value in the array.
<b>Signature:</b>
```typescript
arrayIndexOfAll(search: unknown): FunctionExpression;
```
#### Parameters
| Parameter | Type | Description |
| --- | --- | --- |
| search | unknown | The value to search for. |
<b>Returns:</b>
[FunctionExpression](./firestore_pipelines.functionexpression.md#functionexpression_class)
A new `Expression` representing the indices.
### Example
```typescript
// Get all indices of the value 3 in the 'myArray' field.
field("myArray").arrayIndexOfAll(3);
```
## Expression.arrayIndexOfAll()
Returns all indices of the search value in the array.
<b>Signature:</b>
```typescript
arrayIndexOfAll(search: Expression): FunctionExpression;
```
#### Parameters
| Parameter | Type | Description |
| --- | --- | --- |
| search | [Expression](./firestore_pipelines.expression.md#expression_class) | An expression evaluating to the value to search for. |
<b>Returns:</b>
[FunctionExpression](./firestore_pipelines.functionexpression.md#functionexpression_class)
A new `Expression` representing the indices.
### Example
```typescript
// Get all indices of the value in 'searchVal' field in the 'myArray' field.
field("myArray").arrayIndexOfAll(field("searchVal"));
```
## Expression.arrayLast()
Returns the last element of the array.
<b>Signature:</b>
```typescript
arrayLast(): FunctionExpression;
```
<b>Returns:</b>
[FunctionExpression](./firestore_pipelines.functionexpression.md#functionexpression_class)
A new `Expression` representing the last element.
### Example
```typescript
// Get the last element of the 'myArray' field.
field("myArray").arrayLast();
```
## Expression.arrayLastIndexOf()
Returns the last index of the search value in the array, or -1 if not found.
<b>Signature:</b>
```typescript
arrayLastIndexOf(search: unknown): FunctionExpression;
```
#### Parameters
| Parameter | Type | Description |
| --- | --- | --- |
| search | unknown | The value to search for. |
<b>Returns:</b>
[FunctionExpression](./firestore_pipelines.functionexpression.md#functionexpression_class)
A new `Expression` representing the index.
### Example
```typescript
// Get the last index of the value 3 in the 'myArray' field.
field("myArray").arrayLastIndexOf(3);
```
## Expression.arrayLastIndexOf()
Returns the last index of the search value in the array, or -1 if not found.
<b>Signature:</b>
```typescript
arrayLastIndexOf(search: Expression): FunctionExpression;
```
#### Parameters
| Parameter | Type | Description |
| --- | --- | --- |
| search | [Expression](./firestore_pipelines.expression.md#expression_class) | An expression evaluating to the value to search for. |
<b>Returns:</b>
[FunctionExpression](./firestore_pipelines.functionexpression.md#functionexpression_class)
A new `Expression` representing the index.
### Example
```typescript
// Get the last index of the value in 'searchVal' field in the 'myArray' field.
field("myArray").arrayLastIndexOf(field("searchVal"));
```
## Expression.arrayLastN()
Returns the last `n` elements of the array.
<b>Signature:</b>
```typescript
arrayLastN(n: number): FunctionExpression;
```
#### Parameters
| Parameter | Type | Description |
| --- | --- | --- |
| n | number | The number of elements to return. |
<b>Returns:</b>
[FunctionExpression](./firestore_pipelines.functionexpression.md#functionexpression_class)
A new `Expression` representing the last `n` elements.
### Example
```typescript
// Get the last 3 elements of the 'myArray' field.
field("myArray").arrayLastN(3);
```
## Expression.arrayLastN()
Returns the last `n` elements of the array.
<b>Signature:</b>
```typescript
arrayLastN(n: Expression): FunctionExpression;
```
#### Parameters
| Parameter | Type | Description |
| --- | --- | --- |
| n | [Expression](./firestore_pipelines.expression.md#expression_class) | An expression evaluating to the number of elements to return. |
<b>Returns:</b>
[FunctionExpression](./firestore_pipelines.functionexpression.md#functionexpression_class)
A new `Expression` representing the last `n` elements.
### Example
```typescript
// Get the last n elements of the 'myArray' field.
field("myArray").arrayLastN(field("count"));
```
## Expression.arrayLength()
Creates an expression that calculates the length of an array.
<b>Signature:</b>
```typescript
arrayLength(): FunctionExpression;
```
<b>Returns:</b>
[FunctionExpression](./firestore_pipelines.functionexpression.md#functionexpression_class)
A new `Expression` representing the length of the array.
### Example
```typescript
// Get the number of items in the 'cart' array
field("cart").arrayLength();
```
## Expression.arrayMaximum()
Returns the maximum value in the array.
<b>Signature:</b>
```typescript
arrayMaximum(): FunctionExpression;
```
<b>Returns:</b>
[FunctionExpression](./firestore_pipelines.functionexpression.md#functionexpression_class)
A new `Expression` representing the maximum value.
### Example
```typescript
// Get the maximum value of the 'myArray' field.
field("myArray").arrayMaximum();
```
## Expression.arrayMaximumN()
Returns the largest `n` elements of the array.
Note: Returns the n largest non-null elements in the array, in descending order. This does not use a stable sort, meaning the order of equivalent elements is undefined.
<b>Signature:</b>
```typescript
arrayMaximumN(n: number): FunctionExpression;
```
#### Parameters
| Parameter | Type | Description |
| --- | --- | --- |
| n | number | The number of elements to return. |
<b>Returns:</b>
[FunctionExpression](./firestore_pipelines.functionexpression.md#functionexpression_class)
A new `Expression` representing the largest `n` elements.
### Example
```typescript
// Get the largest 3 elements of the 'myArray' field.
field("myArray").arrayMaximumN(3);
```
## Expression.arrayMaximumN()
Returns the largest `n` elements of the array.
Note: Returns the n largest non-null elements in the array, in descending order. This does not use a stable sort, meaning the order of equivalent elements is undefined.
<b>Signature:</b>
```typescript
arrayMaximumN(n: Expression): FunctionExpression;
```
#### Parameters
| Parameter | Type | Description |
| --- | --- | --- |
| n | [Expression](./firestore_pipelines.expression.md#expression_class) | An expression evaluating to the number of elements to return. |
<b>Returns:</b>
[FunctionExpression](./firestore_pipelines.functionexpression.md#functionexpression_class)
A new `Expression` representing the largest `n` elements.
### Example
```typescript
// Get the largest n elements of the 'myArray' field.
field("myArray").arrayMaximumN(field("count"));
```
## Expression.arrayMinimum()
Returns the minimum value in the array.
<b>Signature:</b>
```typescript
arrayMinimum(): FunctionExpression;
```
<b>Returns:</b>
[FunctionExpression](./firestore_pipelines.functionexpression.md#functionexpression_class)
A new `Expression` representing the minimum value.
### Example
```typescript
// Get the minimum value of the 'myArray' field.
field("myArray").arrayMinimum();
```
## Expression.arrayMinimumN()
Returns the smallest `n` elements of the array.
Note: Returns the n smallest non-null elements in the array, in ascending order. This does not use a stable sort, meaning the order of equivalent elements is undefined.
<b>Signature:</b>
```typescript
arrayMinimumN(n: number): FunctionExpression;
```
#### Parameters
| Parameter | Type | Description |
| --- | --- | --- |
| n | number | The number of elements to return. |
<b>Returns:</b>
[FunctionExpression](./firestore_pipelines.functionexpression.md#functionexpression_class)
A new `Expression` representing the smallest `n` elements.
### Example
```typescript
// Get the smallest 3 elements of the 'myArray' field.
field("myArray").arrayMinimumN(3);
```
## Expression.arrayMinimumN()
Returns the smallest `n` elements of the array.
Note: Returns the n smallest non-null elements in the array, in ascending order. This does not use a stable sort, meaning the order of equivalent elements is undefined.
<b>Signature:</b>
```typescript
arrayMinimumN(n: Expression): FunctionExpression;
```
#### Parameters
| Parameter | Type | Description |
| --- | --- | --- |
| n | [Expression](./firestore_pipelines.expression.md#expression_class) | An expression evaluating to the number of elements to return. |
<b>Returns:</b>
[FunctionExpression](./firestore_pipelines.functionexpression.md#functionexpression_class)
A new `Expression` representing the smallest `n` elements.
### Example
```typescript
// Get the smallest n elements of the 'myArray' field.
field("myArray").arrayMinimumN(field("count"));
```
## Expression.arrayReverse()
Creates an expression that reverses an array.
<b>Signature:</b>
```typescript
arrayReverse(): FunctionExpression;
```
<b>Returns:</b>
[FunctionExpression](./firestore_pipelines.functionexpression.md#functionexpression_class)
A new [Expression](./firestore_pipelines.expression.md#expression_class) representing the reversed array.
### Example
```typescript
// Reverse the value of the 'myArray' field.
field("myArray").arrayReverse();
```
## Expression.arraySlice()
Returns a subset of the array.
<b>Signature:</b>
```typescript
arraySlice(offset: number | Expression, length?: number | Expression): FunctionExpression;
```
#### Parameters
| Parameter | Type | Description |
| --- | --- | --- |
| offset | number \| [Expression](./firestore_pipelines.expression.md#expression_class) | The starting offset. |
| length | number \| [Expression](./firestore_pipelines.expression.md#expression_class) | The optional length of the slice. |
<b>Returns:</b>
[FunctionExpression](./firestore_pipelines.functionexpression.md#functionexpression_class)
A new `Expression` representing the sliced array.
### Example
```typescript
// Get 5 elements from the 'items' array starting from index 2
field("items").arraySlice(2, 5);
// Get n number of elements from the 'items' array starting from index 2
field("items").arraySlice(2, field("count"));
```
## Expression.arraySum()
Creates an expression that computes the sum of the elements in an array.
<b>Signature:</b>
```typescript
arraySum(): FunctionExpression;
```
<b>Returns:</b>
[FunctionExpression](./firestore_pipelines.functionexpression.md#functionexpression_class)
A new [Expression](./firestore_pipelines.expression.md#expression_class) representing the sum of the elements in the array.
### Example
```typescript
// Compute the sum of the elements in the 'scores' field.
field("scores").arraySum();
```
## Expression.arrayTransform()
Creates an expression that applies a provided transformation to each element in an array.
<b>Signature:</b>
```typescript
arrayTransform(elementAlias: string, transform: Expression): FunctionExpression;
```
#### Parameters
| Parameter | Type | Description |
| --- | --- | --- |
| elementAlias | string | The variable name to use for each element. |
| transform | [Expression](./firestore_pipelines.expression.md#expression_class) | The lambda expression used to transform the elements. |
<b>Returns:</b>
[FunctionExpression](./firestore_pipelines.functionexpression.md#functionexpression_class)
A new `Expression` representing the arrayTransform operation.
### Example
```typescript
// Transform the 'scores' array by multiplying each score by 10
field("scores").arrayTransform("score", multiply(variable("score"), 10));
```
## Expression.arrayTransformWithIndex()
Creates an expression that applies a provided transformation to each element in an array, providing the element's index to the transformation expression.
<b>Signature:</b>
```typescript
arrayTransformWithIndex(elementAlias: string, indexAlias: string, transform: Expression): FunctionExpression;
```
#### Parameters
| Parameter | Type | Description |
| --- | --- | --- |
| elementAlias | string | The variable name to use for each element. |
| indexAlias | string | The variable name to use for the current index. |
| transform | [Expression](./firestore_pipelines.expression.md#expression_class) | The lambda expression used to transform the elements. |
<b>Returns:</b>
[FunctionExpression](./firestore_pipelines.functionexpression.md#functionexpression_class)
A new `Expression` representing the arrayTransformWithIndex operation.
### Example
```typescript
// Transform the 'scores' array by adding the index to each score
field("scores").arrayTransformWithIndex("score", "i", add(variable("score"), variable("i")));
```
## Expression.as()
Assigns an alias to this expression.
Aliases are useful for renaming fields in the output of a stage or for giving meaningful names to calculated values.
<b>Signature:</b>
```typescript
as(name: string): AliasedExpression;
```
#### Parameters
| Parameter | Type | Description |
| --- | --- | --- |
| name | string | The alias to assign to this expression. |
<b>Returns:</b>
[AliasedExpression](./firestore_pipelines.aliasedexpression.md#aliasedexpression_class)
A new [AliasedExpression](./firestore_pipelines.aliasedexpression.md#aliasedexpression_class) that wraps this expression and associates it with the provided alias.
### Example
```typescript
// Calculate the total price and assign it the alias "totalPrice" and add it to the output.
firestore.pipeline().collection("items")
.addFields(field("price").multiply(field("quantity")).as("totalPrice"));
```
## Expression.asBoolean()
Wraps the expression in a \[BooleanExpression\].
<b>Signature:</b>
```typescript
asBoolean(): BooleanExpression;
```
<b>Returns:</b>
[BooleanExpression](./firestore_pipelines.booleanexpression.md#booleanexpression_class)
A \[BooleanExpression\] representing the same expression.
## Expression.ascending()
Creates an [Ordering](./firestore_pipelines.ordering.md#ordering_class) that sorts documents in ascending order based on this expression.
<b>Signature:</b>
```typescript
ascending(): Ordering;
```
<b>Returns:</b>
[Ordering](./firestore_pipelines.ordering.md#ordering_class)
A new `Ordering` for ascending sorting.
### Example
```typescript
// Sort documents by the 'name' field in ascending order
firestore.pipeline().collection("users")
.sort(field("name").ascending());
```
## Expression.average()
Creates an aggregation that calculates the average (mean) of a numeric field across multiple stage inputs.
<b>Signature:</b>
```typescript
average(): AggregateFunction;
```
<b>Returns:</b>
[AggregateFunction](./firestore_pipelines.aggregatefunction.md#aggregatefunction_class)
A new `AggregateFunction` representing the 'average' aggregation.
### Example
```typescript
// Calculate the average age of users
field("age").average().as("averageAge");
```
## Expression.byteLength()
Creates an expression that calculates the length of this string expression in bytes.
<b>Signature:</b>
```typescript
byteLength(): FunctionExpression;
```
<b>Returns:</b>
[FunctionExpression](./firestore_pipelines.functionexpression.md#functionexpression_class)
A new [Expression](./firestore_pipelines.expression.md#expression_class) representing the length of the string in bytes.
### Example
```typescript
// Calculate the length of the 'myString' field in bytes.
field("myString").byteLength();
```
## Expression.ceil()
Creates an expression that computes the ceiling of a numeric value.
<b>Signature:</b>
```typescript
ceil(): FunctionExpression;
```
<b>Returns:</b>
[FunctionExpression](./firestore_pipelines.functionexpression.md#functionexpression_class)
A new [Expression](./firestore_pipelines.expression.md#expression_class) representing the ceiling of the numeric value.
### Example
```typescript
// Compute the ceiling of the 'price' field.
field("price").ceil();
```
## Expression.charLength()
Creates an expression that calculates the character length of a string in UTF-8.
<b>Signature:</b>
```typescript
charLength(): FunctionExpression;
```
<b>Returns:</b>
[FunctionExpression](./firestore_pipelines.functionexpression.md#functionexpression_class)
A new `Expression` representing the length of the string.
### Example
```typescript
// Get the character length of the 'name' field in its UTF-8 form.
field("name").charLength();
```
## Expression.coalesce()
Creates an expression that returns the first non-null, non-absent argument, without evaluating the rest of the arguments. When all arguments are null or absent, returns the last argument.
<b>Signature:</b>
```typescript
coalesce(replacement: Expression | unknown, ...others: Array<Expression | unknown>): FunctionExpression;
```
#### Parameters
| Parameter | Type | Description |
| --- | --- | --- |
| replacement | [Expression](./firestore_pipelines.expression.md#expression_class) \| unknown | The value to use if this expression evaluates to null. |
| others | Array&lt;[Expression](./firestore_pipelines.expression.md#expression_class) \| unknown&gt; | Optional additional values to check if previous values are null. |
<b>Returns:</b>
[FunctionExpression](./firestore_pipelines.functionexpression.md#functionexpression_class)
A new `Expression` representing the coalesce operation.
### Example
```typescript
// Returns the value of the first non-null, non-absent field among 'preferredName', 'fullName',
// or the last argument if all previous fields are null.
field("preferredName").coalesce(field("fullName"), "Anonymous");
```
## Expression.collectionId()
Creates an expression that returns the collection ID from a path.
<b>Signature:</b>
```typescript
collectionId(): FunctionExpression;
```
<b>Returns:</b>
[FunctionExpression](./firestore_pipelines.functionexpression.md#functionexpression_class)
A new [Expression](./firestore_pipelines.expression.md#expression_class) representing the collectionId operation.
### Example
```typescript
// Get the collection ID from a path.
field("__path__").collectionId();
```
## Expression.concat()
Creates an expression that concatenates expression results together.
<b>Signature:</b>
```typescript
concat(second: Expression | unknown, ...others: Array<Expression | unknown>): FunctionExpression;
```
#### Parameters
| Parameter | Type | Description |
| --- | --- | --- |
| second | [Expression](./firestore_pipelines.expression.md#expression_class) \| unknown | The additional expression or literal to concatenate. |
| others | Array&lt;[Expression](./firestore_pipelines.expression.md#expression_class) \| unknown&gt; | Optional additional expressions or literals to concatenate. |
<b>Returns:</b>
[FunctionExpression](./firestore_pipelines.functionexpression.md#functionexpression_class)
A new `Expression` representing the concatenated value.
### Example
```typescript
// Combine the 'firstName', ' ', and 'lastName' fields into a single value.
field("firstName").concat(constant(" "), field("lastName"));
```
## Expression.cosineDistance()
Calculates the cosine distance between two vectors.
<b>Signature:</b>
```typescript
cosineDistance(vectorExpression: Expression): FunctionExpression;
```
#### Parameters
| Parameter | Type | Description |
| --- | --- | --- |
| vectorExpression | [Expression](./firestore_pipelines.expression.md#expression_class) | The other vector (represented as an Expression) to compare against. |
<b>Returns:</b>
[FunctionExpression](./firestore_pipelines.functionexpression.md#functionexpression_class)
A new `Expression` representing the cosine distance between the two vectors.
### Example
```typescript
// Calculate the cosine distance between the 'userVector' field and the 'itemVector' field
field("userVector").cosineDistance(field("itemVector"));
```
## Expression.cosineDistance()
Calculates the Cosine distance between two vectors.
<b>Signature:</b>
```typescript
cosineDistance(vector: VectorValue | number[]): FunctionExpression;
```
#### Parameters
| Parameter | Type | Description |
| --- | --- | --- |
| vector | [VectorValue](./firestore_.vectorvalue.md#vectorvalue_class) \| number\[\] | The other vector (as a VectorValue) to compare against. |
<b>Returns:</b>
[FunctionExpression](./firestore_pipelines.functionexpression.md#functionexpression_class)
A new `Expression` representing the Cosine\* distance between the two vectors.
### Example
```typescript
// Calculate the Cosine distance between the 'location' field and a target location
field("location").cosineDistance(new VectorValue([37.7749, -122.4194]));
```
## Expression.count()
Creates an aggregation that counts the number of stage inputs with valid evaluations of the expression or field.
<b>Signature:</b>
```typescript
count(): AggregateFunction;
```
<b>Returns:</b>
[AggregateFunction](./firestore_pipelines.aggregatefunction.md#aggregatefunction_class)
A new `AggregateFunction` representing the 'count' aggregation.
### Example
```typescript
// Count the total number of products
field("productId").count().as("totalProducts");
```
## Expression.countDistinct()
Creates an aggregation that counts the number of distinct values of the expression or field.
<b>Signature:</b>
```typescript
countDistinct(): AggregateFunction;
```
<b>Returns:</b>
[AggregateFunction](./firestore_pipelines.aggregatefunction.md#aggregatefunction_class)
A new `AggregateFunction` representing the 'count\_distinct' aggregation.
### Example
```typescript
// Count the distinct number of products
field("productId").countDistinct().as("distinctProducts");
```
## Expression.descending()
Creates an [Ordering](./firestore_pipelines.ordering.md#ordering_class) that sorts documents in descending order based on this expression.
<b>Signature:</b>
```typescript
descending(): Ordering;
```
<b>Returns:</b>
[Ordering](./firestore_pipelines.ordering.md#ordering_class)
A new `Ordering` for descending sorting.
### Example
```typescript
// Sort documents by the 'createdAt' field in descending order
firestore.pipeline().collection("users")
.sort(field("createdAt").descending());
```
## Expression.divide()
Creates an expression that divides this expression by another expression.
<b>Signature:</b>
```typescript
divide(divisor: Expression): FunctionExpression;
```
#### Parameters
| Parameter | Type | Description |
| --- | --- | --- |
| divisor | [Expression](./firestore_pipelines.expression.md#expression_class) | The expression to divide by. |
<b>Returns:</b>
[FunctionExpression](./firestore_pipelines.functionexpression.md#functionexpression_class)
A new `Expression` representing the division operation.
### Example
```typescript
// Divide the 'total' field by the 'count' field
field("total").divide(field("count"));
```
## Expression.divide()
Creates an expression that divides this expression by a constant value.
<b>Signature:</b>
```typescript
divide(divisor: number): FunctionExpression;
```
#### Parameters
| Parameter | Type | Description |
| --- | --- | --- |
| divisor | number | The constant value to divide by. |
<b>Returns:</b>
[FunctionExpression](./firestore_pipelines.functionexpression.md#functionexpression_class)
A new `Expression` representing the division operation.
### Example
```typescript
// Divide the 'value' field by 10
field("value").divide(10);
```
## Expression.documentId()
Creates an expression that returns the document ID from a path.
<b>Signature:</b>
```typescript
documentId(): FunctionExpression;
```
<b>Returns:</b>
[FunctionExpression](./firestore_pipelines.functionexpression.md#functionexpression_class)
A new [Expression](./firestore_pipelines.expression.md#expression_class) representing the documentId operation.
### Example
```typescript
// Get the document ID from a path.
field("__path__").documentId();
```
## Expression.dotProduct()
Calculates the dot product between two vectors.
<b>Signature:</b>
```typescript
dotProduct(vectorExpression: Expression): FunctionExpression;
```
#### Parameters
| Parameter | Type | Description |
| --- | --- | --- |
| vectorExpression | [Expression](./firestore_pipelines.expression.md#expression_class) | The other vector (as an array of numbers) to calculate with. |
<b>Returns:</b>
[FunctionExpression](./firestore_pipelines.functionexpression.md#functionexpression_class)
A new `Expression` representing the dot product between the two vectors.
### Example
```typescript
// Calculate the dot product between a feature vector and a target vector
field("features").dotProduct([0.5, 0.8, 0.2]);
```
## Expression.dotProduct()
Calculates the dot product between two vectors.
<b>Signature:</b>
```typescript
dotProduct(vector: VectorValue | number[]): FunctionExpression;
```
#### Parameters
| Parameter | Type | Description |
| --- | --- | --- |
| vector | [VectorValue](./firestore_.vectorvalue.md#vectorvalue_class) \| number\[\] | The other vector (as an array of numbers) to calculate with. |
<b>Returns:</b>
[FunctionExpression](./firestore_pipelines.functionexpression.md#functionexpression_class)
A new `Expression` representing the dot product between the two vectors.
### Example
```typescript
// Calculate the dot product between a feature vector and a target vector
field("features").dotProduct(new VectorValue([0.5, 0.8, 0.2]));
```
## Expression.endsWith()
Creates an expression that checks if a string ends with a given postfix.
<b>Signature:</b>
```typescript
endsWith(suffix: string): BooleanExpression;
```
#### Parameters
| Parameter | Type | Description |
| --- | --- | --- |
| suffix | string | The postfix to check for. |
<b>Returns:</b>
[BooleanExpression](./firestore_pipelines.booleanexpression.md#booleanexpression_class)
A new `Expression` representing the 'ends with' comparison.
### Example
```typescript
// Check if the 'filename' field ends with ".txt"
field("filename").endsWith(".txt");
```
## Expression.endsWith()
Creates an expression that checks if a string ends with a given postfix (represented as an expression).
<b>Signature:</b>
```typescript
endsWith(suffix: Expression): BooleanExpression;
```
#### Parameters
| Parameter | Type | Description |
| --- | --- | --- |
| suffix | [Expression](./firestore_pipelines.expression.md#expression_class) | The postfix expression to check for. |
<b>Returns:</b>
[BooleanExpression](./firestore_pipelines.booleanexpression.md#booleanexpression_class)
A new `Expression` representing the 'ends with' comparison.
### Example
```typescript
// Check if the 'url' field ends with the value of the 'extension' field
field("url").endsWith(field("extension"));
```
## Expression.equal()
Creates an expression that checks if this expression is equal to another expression.
<b>Signature:</b>
```typescript
equal(expression: Expression): BooleanExpression;
```
#### Parameters
| Parameter | Type | Description |
| --- | --- | --- |
| expression | [Expression](./firestore_pipelines.expression.md#expression_class) | The expression to compare for equality. |
<b>Returns:</b>
[BooleanExpression](./firestore_pipelines.booleanexpression.md#booleanexpression_class)
A new `Expression` representing the equality comparison.
### Example
```typescript
// Check if the 'age' field is equal to 21
field("age").equal(21);
```
## Expression.equal()
Creates an expression that checks if this expression is equal to a constant value.
<b>Signature:</b>
```typescript
equal(value: unknown): BooleanExpression;
```
#### Parameters
| Parameter | Type | Description |
| --- | --- | --- |
| value | unknown | The constant value to compare for equality. |
<b>Returns:</b>
[BooleanExpression](./firestore_pipelines.booleanexpression.md#booleanexpression_class)
A new `Expression` representing the equality comparison.
### Example
```typescript
// Check if the 'city' field is equal to "London"
field("city").equal("London");
```
## Expression.equalAny()
Creates an expression that checks if this expression is equal to any of the provided values or expressions.
<b>Signature:</b>
```typescript
equalAny(values: Array<Expression | unknown>): BooleanExpression;
```
#### Parameters
| Parameter | Type | Description |
| --- | --- | --- |
| values | Array&lt;[Expression](./firestore_pipelines.expression.md#expression_class) \| unknown&gt; | The values or expressions to check against. |
<b>Returns:</b>
[BooleanExpression](./firestore_pipelines.booleanexpression.md#booleanexpression_class)
A new `Expression` representing the 'IN' comparison.
### Example
```typescript
// Check if the 'category' field is either "Electronics" or value of field 'primaryType'
field("category").equalAny(["Electronics", field("primaryType")]);
```
## Expression.equalAny()
Creates an expression that checks if this expression is equal to any of the provided values or expressions.
<b>Signature:</b>
```typescript
equalAny(arrayExpression: Expression): BooleanExpression;
```
#### Parameters
| Parameter | Type | Description |
| --- | --- | --- |
| arrayExpression | [Expression](./firestore_pipelines.expression.md#expression_class) | An expression that evaluates to an array of values to check against. |
<b>Returns:</b>
[BooleanExpression](./firestore_pipelines.booleanexpression.md#booleanexpression_class)
A new `Expression` representing the 'IN' comparison.
### Example
```typescript
// Check if the 'category' field is either "Electronics" or value of field 'primaryType'
field("category").equalAny(array(["Electronics", field("primaryType")]));
```
## Expression.euclideanDistance()
Calculates the Euclidean distance between two vectors.
<b>Signature:</b>
```typescript
euclideanDistance(vectorExpression: Expression): FunctionExpression;
```
#### Parameters
| Parameter | Type | Description |
| --- | --- | --- |
| vectorExpression | [Expression](./firestore_pipelines.expression.md#expression_class) | The other vector (as an array of numbers) to calculate with. |
<b>Returns:</b>
[FunctionExpression](./firestore_pipelines.functionexpression.md#functionexpression_class)
A new `Expression` representing the Euclidean distance between the two vectors.
### Example
```typescript
// Calculate the Euclidean distance between the 'location' field and a target location
field("location").euclideanDistance([37.7749, -122.4194]);
```
## Expression.euclideanDistance()
Calculates the Euclidean distance between two vectors.
<b>Signature:</b>
```typescript
euclideanDistance(vector: VectorValue | number[]): FunctionExpression;
```
#### Parameters
| Parameter | Type | Description |
| --- | --- | --- |
| vector | [VectorValue](./firestore_.vectorvalue.md#vectorvalue_class) \| number\[\] | The other vector (as a VectorValue) to compare against. |
<b>Returns:</b>
[FunctionExpression](./firestore_pipelines.functionexpression.md#functionexpression_class)
A new `Expression` representing the Euclidean distance between the two vectors.
### Example
```typescript
// Calculate the Euclidean distance between the 'location' field and a target location
field("location").euclideanDistance(new VectorValue([37.7749, -122.4194]));
```
## Expression.exists()
Creates an expression that checks if a field exists in the document.
<b>Signature:</b>
```typescript
exists(): BooleanExpression;
```
<b>Returns:</b>
[BooleanExpression](./firestore_pipelines.booleanexpression.md#booleanexpression_class)
A new `Expression` representing the 'exists' check.
### Example
```typescript
// Check if the document has a field named "phoneNumber"
field("phoneNumber").exists();
```
## Expression.exp()
Creates an expression that computes e to the power of this expression.
<b>Signature:</b>
```typescript
exp(): FunctionExpression;
```
<b>Returns:</b>
[FunctionExpression](./firestore_pipelines.functionexpression.md#functionexpression_class)
A new [Expression](./firestore_pipelines.expression.md#expression_class) representing the exp of the numeric value.
### Example
```typescript
// Compute e to the power of the 'value' field.
field("value").exp();
```
## Expression.first()
Creates an aggregation that finds the first value of an expression across multiple stage inputs.
<b>Signature:</b>
```typescript
first(): AggregateFunction;
```
<b>Returns:</b>
[AggregateFunction](./firestore_pipelines.aggregatefunction.md#aggregatefunction_class)
A new `AggregateFunction` representing the 'first' aggregation.
### Example
```typescript
// Find the first value of the 'rating' field
field("rating").first().as("firstRating");
```
## Expression.floor()
Creates an expression that computes the floor of a numeric value.
<b>Signature:</b>
```typescript
floor(): FunctionExpression;
```
<b>Returns:</b>
[FunctionExpression](./firestore_pipelines.functionexpression.md#functionexpression_class)
A new [Expression](./firestore_pipelines.expression.md#expression_class) representing the floor of the numeric value.
### Example
```typescript
// Compute the floor of the 'price' field.
field("price").floor();
```
## Expression.getField()
Creates an expression that returns the value of a field from the document that results from the evaluation of this expression.
<b>Signature:</b>
```typescript
getField(key: string | Expression): Expression;
```
#### Parameters
| Parameter | Type | Description |
| --- | --- | --- |
| key | string \| [Expression](./firestore_pipelines.expression.md#expression_class) | The field to access in the document. |
<b>Returns:</b>
[Expression](./firestore_pipelines.expression.md#expression_class)
A new `Expression` representing the value of the field in the document.
### Example
```typescript
// Get the value of the "city" field in the "address" document.
field("address").getField("city")
```
## Expression.greaterThan()
Creates an expression that checks if this expression is greater than another expression.
<b>Signature:</b>
```typescript
greaterThan(expression: Expression): BooleanExpression;
```
#### Parameters
| Parameter | Type | Description |
| --- | --- | --- |
| expression | [Expression](./firestore_pipelines.expression.md#expression_class) | The expression to compare for greater than. |
<b>Returns:</b>
[BooleanExpression](./firestore_pipelines.booleanexpression.md#booleanexpression_class)
A new `Expression` representing the greater than comparison.
### Example
```typescript
// Check if the 'age' field is greater than the 'limit' field
field("age").greaterThan(field("limit"));
```
## Expression.greaterThan()
Creates an expression that checks if this expression is greater than a constant value.
<b>Signature:</b>
```typescript
greaterThan(value: unknown): BooleanExpression;
```
#### Parameters
| Parameter | Type | Description |
| --- | --- | --- |
| value | unknown | The constant value to compare for greater than. |
<b>Returns:</b>
[BooleanExpression](./firestore_pipelines.booleanexpression.md#booleanexpression_class)
A new `Expression` representing the greater than comparison.
### Example
```typescript
// Check if the 'price' field is greater than 100
field("price").greaterThan(100);
```
## Expression.greaterThanOrEqual()
Creates an expression that checks if this expression is greater than or equal to another expression.
<b>Signature:</b>
```typescript
greaterThanOrEqual(expression: Expression): BooleanExpression;
```
#### Parameters
| Parameter | Type | Description |
| --- | --- | --- |
| expression | [Expression](./firestore_pipelines.expression.md#expression_class) | The expression to compare for greater than or equal to. |
<b>Returns:</b>
[BooleanExpression](./firestore_pipelines.booleanexpression.md#booleanexpression_class)
A new `Expression` representing the greater than or equal to comparison.
### Example
```typescript
// Check if the 'quantity' field is greater than or equal to field 'requirement' plus 1
field("quantity").greaterThanOrEqual(field('requirement').add(1));
```
## Expression.greaterThanOrEqual()
Creates an expression that checks if this expression is greater than or equal to a constant value.
<b>Signature:</b>
```typescript
greaterThanOrEqual(value: unknown): BooleanExpression;
```
#### Parameters
| Parameter | Type | Description |
| --- | --- | --- |
| value | unknown | The constant value to compare for greater than or equal to. |
<b>Returns:</b>
[BooleanExpression](./firestore_pipelines.booleanexpression.md#booleanexpression_class)
A new `Expression` representing the greater than or equal to comparison.
### Example
```typescript
// Check if the 'score' field is greater than or equal to 80
field("score").greaterThanOrEqual(80);
```
## Expression.ifAbsent()
Creates an expression that returns the `elseValue` argument if this expression results in an absent value, else return the result of this expression evaluation.
<b>Signature:</b>
```typescript
ifAbsent(elseValue: unknown): Expression;
```
#### Parameters
| Parameter | Type | Description |
| --- | --- | --- |
| elseValue | unknown | The value that will be returned if this Expression evaluates to an absent value. |
<b>Returns:</b>
[Expression](./firestore_pipelines.expression.md#expression_class)
A new \[Expression\] representing the ifAbsent operation.
### Example
```typescript
// Returns the value of the optional field 'optional_field', or returns 'default_value'
// if the field is absent.
field("optional_field").ifAbsent("default_value")
```
## Expression.ifAbsent()
Creates an expression that returns the `elseValue` argument if this expression results in an absent value, else return the result of this expression evaluation.
<b>Signature:</b>
```typescript
ifAbsent(elseExpression: unknown): Expression;
```
#### Parameters
| Parameter | Type | Description |
| --- | --- | --- |
| elseExpression | unknown | The Expression that will be evaluated if this Expression evaluates to an absent value. |
<b>Returns:</b>
[Expression](./firestore_pipelines.expression.md#expression_class)
A new \[Expression\] representing the ifAbsent operation.
### Example
```typescript
// Returns the value of the optional field 'optional_field', or if that is
// absent, then returns the value of the field `default_field`.
field("optional_field").ifAbsent(field('default_field'))
```
## Expression.ifError()
Creates an expression that returns the result of the `catchExpr` argument if there is an error, else return the result of this expression.
<b>Signature:</b>
```typescript
ifError(catchExpr: Expression): FunctionExpression;
```
#### Parameters
| Parameter | Type | Description |
| --- | --- | --- |
| catchExpr | [Expression](./firestore_pipelines.expression.md#expression_class) | The catch expression that will be evaluated and returned if this expression produces an error. |
<b>Returns:</b>
[FunctionExpression](./firestore_pipelines.functionexpression.md#functionexpression_class)
A new [Expression](./firestore_pipelines.expression.md#expression_class) representing the 'ifError' operation.
### Example
```typescript
// Returns the first item in the title field arrays, or returns
// the entire title field if the array is empty or the field is another type.
field("title").arrayGet(0).ifError(field("title"));
```
## Expression.ifError()
Creates an expression that returns the `catch` argument if there is an error, else return the result of this expression.
<b>Signature:</b>
```typescript
ifError(catchValue: unknown): FunctionExpression;
```
#### Parameters
| Parameter | Type | Description |
| --- | --- | --- |
| catchValue | unknown | The value that will be returned if this expression produces an error. |
<b>Returns:</b>
[FunctionExpression](./firestore_pipelines.functionexpression.md#functionexpression_class)
A new [Expression](./firestore_pipelines.expression.md#expression_class) representing the 'ifError' operation.
### Example
```typescript
// Returns the first item in the title field arrays, or returns
// "Default Title"
field("title").arrayGet(0).ifError("Default Title");
```
## Expression.ifNull()
Creates an expression that returns the `elseValue` argument if this expression evaluates to null, else return the result of this expression evaluation.
This function provides a fallback for both absent and explicit null values. In contrast, `ifAbsent()` only triggers for missing fields.
<b>Signature:</b>
```typescript
ifNull(elseExpression: Expression): FunctionExpression;
```
#### Parameters
| Parameter | Type | Description |
| --- | --- | --- |
| elseExpression | [Expression](./firestore_pipelines.expression.md#expression_class) | The Expression that will be evaluated if this Expression evaluates to null. |
<b>Returns:</b>
[FunctionExpression](./firestore_pipelines.functionexpression.md#functionexpression_class)
A new `Expression` representing the ifNull operation.
### Example
```typescript
// Returns the user's preferred name, or if that is null, returns their full name.
field("preferredName").ifNull(field("fullName"))
```
## Expression.ifNull()
Creates an expression that returns the `elseValue` argument if this expression evaluates to null, else return the result of this expression evaluation.
This function provides a fallback for both absent and explicit null values. In contrast, `ifAbsent()` only triggers for missing fields.
<b>Signature:</b>
```typescript
ifNull(elseValue: unknown): FunctionExpression;
```
#### Parameters
| Parameter | Type | Description |
| --- | --- | --- |
| elseValue | unknown | The value that will be returned if this Expression evaluates to null. |
<b>Returns:</b>
[FunctionExpression](./firestore_pipelines.functionexpression.md#functionexpression_class)
A new `Expression` representing the ifNull operation.
### Example
```typescript
// Returns the user's display name, or returns "Anonymous" if the field is null.
field("displayName").ifNull("Anonymous")
```
## Expression.isAbsent()
Creates an expression that returns `true` if the result of this expression is absent. Otherwise, returns `false` even if the value is `null`<!-- -->.
<b>Signature:</b>
```typescript
isAbsent(): BooleanExpression;
```
<b>Returns:</b>
[BooleanExpression](./firestore_pipelines.booleanexpression.md#booleanexpression_class)
A new [BooleanExpression](./firestore_pipelines.booleanexpression.md#booleanexpression_class) representing the 'isAbsent' check.
### Example
```typescript
// Check if the field `value` is absent.
field("value").isAbsent();
```
## Expression.isError()
Creates an expression that checks if a given expression produces an error.
<b>Signature:</b>
```typescript
isError(): BooleanExpression;
```
<b>Returns:</b>
[BooleanExpression](./firestore_pipelines.booleanexpression.md#booleanexpression_class)
A new [BooleanExpression](./firestore_pipelines.booleanexpression.md#booleanexpression_class) representing the 'isError' check.
### Example
```typescript
// Check if the result of a calculation is an error
field("title").arrayContains(1).isError();
```
## Expression.isType()
Creates an expression that checks if the result of this expression is of the given type.
Null or undefined fields evaluate to skip/error. Use `ifAbsent()` / `isAbsent()` to evaluate missing data. Supported values for `type` are: `'null'`<!-- -->, `'array'`<!-- -->, `'boolean'`<!-- -->, `'bytes'`<!-- -->, `'timestamp'`<!-- -->, `'geo_point'`<!-- -->, `'number'`<!-- -->, `'int32'`<!-- -->, `'int64'`<!-- -->, `'float64'`<!-- -->, `'decimal128'`<!-- -->, `'map'`<!-- -->, `'reference'`<!-- -->, `'string'`<!-- -->, `'vector'`<!-- -->, `'max_key'`<!-- -->, `'min_key'`<!-- -->, `'object_id'`<!-- -->, `'regex'`<!-- -->, `'request_timestamp'`<!-- -->.
<b>Signature:</b>
```typescript
isType(type: string): BooleanExpression;
```
#### Parameters
| Parameter | Type | Description |
| --- | --- | --- |
| type | string | The type to check for. |
<b>Returns:</b>
[BooleanExpression](./firestore_pipelines.booleanexpression.md#booleanexpression_class)
A new `BooleanExpression` that evaluates to true if the expression's result is of the given type, false otherwise.
### Example
```typescript
// Check if the 'price' field is specifically an integer (not just 'number')
field('price').isType('int64');
```
## Expression.join()
Creates an expression that joins the elements of an array into a string.
<b>Signature:</b>
```typescript
join(delimiterExpression: Expression): Expression;
```
#### Parameters
| Parameter | Type | Description |
| --- | --- | --- |
| delimiterExpression | [Expression](./firestore_pipelines.expression.md#expression_class) | The expression that evaluates to the delimiter string. |
<b>Returns:</b>
[Expression](./firestore_pipelines.expression.md#expression_class)
A new Expression representing the join operation.
### Example
```typescript
// Join the elements of the 'tags' field with the delimiter from the 'separator' field.
field("tags").join(field("separator"))
```
## Expression.join()
Creates an expression that joins the elements of an array field into a string.
<b>Signature:</b>
```typescript
join(delimiter: string): Expression;
```
#### Parameters
| Parameter | Type | Description |
| --- | --- | --- |
| delimiter | string | The string to use as a delimiter. |
<b>Returns:</b>
[Expression](./firestore_pipelines.expression.md#expression_class)
A new Expression representing the join operation.
### Example
```typescript
// Join the elements of the 'tags' field with a comma and space.
field("tags").join(", ")
```
## Expression.last()
Creates an aggregation that finds the last value of an expression across multiple stage inputs.
<b>Signature:</b>
```typescript
last(): AggregateFunction;
```
<b>Returns:</b>
[AggregateFunction](./firestore_pipelines.aggregatefunction.md#aggregatefunction_class)
A new `AggregateFunction` representing the 'last' aggregation.
### Example
```typescript
// Find the last value of the 'rating' field
field("rating").last().as("lastRating");
```
## Expression.length()
Creates an expression that calculates the length of a string, array, map, vector, or bytes.
<b>Signature:</b>
```typescript
length(): FunctionExpression;
```
<b>Returns:</b>
[FunctionExpression](./firestore_pipelines.functionexpression.md#functionexpression_class)
A new `Expression` representing the length of the string, array, map, vector, or bytes.
### Example
```typescript
// Get the length of the 'name' field.
field("name").length();
// Get the number of items in the 'cart' array.
field("cart").length();
```
## Expression.lessThan()
Creates an expression that checks if this expression is less than another expression.
<b>Signature:</b>
```typescript
lessThan(experession: Expression): BooleanExpression;
```
#### Parameters
| Parameter | Type | Description |
| --- | --- | --- |
| experession | [Expression](./firestore_pipelines.expression.md#expression_class) | The expression to compare for less than. |
<b>Returns:</b>
[BooleanExpression](./firestore_pipelines.booleanexpression.md#booleanexpression_class)
A new `Expression` representing the less than comparison.
### Example
```typescript
// Check if the 'age' field is less than 'limit'
field("age").lessThan(field('limit'));
```
## Expression.lessThan()
Creates an expression that checks if this expression is less than a constant value.
<b>Signature:</b>
```typescript
lessThan(value: unknown): BooleanExpression;
```
#### Parameters
| Parameter | Type | Description |
| --- | --- | --- |
| value | unknown | The constant value to compare for less than. |
<b>Returns:</b>
[BooleanExpression](./firestore_pipelines.booleanexpression.md#booleanexpression_class)
A new `Expression` representing the less than comparison.
### Example
```typescript
// Check if the 'price' field is less than 50
field("price").lessThan(50);
```
## Expression.lessThanOrEqual()
Creates an expression that checks if this expression is less than or equal to another expression.
<b>Signature:</b>
```typescript
lessThanOrEqual(expression: Expression): BooleanExpression;
```
#### Parameters
| Parameter | Type | Description |
| --- | --- | --- |
| expression | [Expression](./firestore_pipelines.expression.md#expression_class) | The expression to compare for less than or equal to. |
<b>Returns:</b>
[BooleanExpression](./firestore_pipelines.booleanexpression.md#booleanexpression_class)
A new `Expression` representing the less than or equal to comparison.
### Example
```typescript
// Check if the 'quantity' field is less than or equal to 20
field("quantity").lessThan(constant(20));
```
## Expression.lessThanOrEqual()
Creates an expression that checks if this expression is less than or equal to a constant value.
<b>Signature:</b>
```typescript
lessThanOrEqual(value: unknown): BooleanExpression;
```
#### Parameters
| Parameter | Type | Description |
| --- | --- | --- |
| value | unknown | The constant value to compare for less than or equal to. |
<b>Returns:</b>
[BooleanExpression](./firestore_pipelines.booleanexpression.md#booleanexpression_class)
A new `Expression` representing the less than or equal to comparison.
### Example
```typescript
// Check if the 'score' field is less than or equal to 70
field("score").lessThan(70);
```
## Expression.like()
Creates an expression that performs a case-sensitive string comparison.
<b>Signature:</b>
```typescript
like(pattern: string): BooleanExpression;
```
#### Parameters
| Parameter | Type | Description |
| --- | --- | --- |
| pattern | string | The pattern to search for. You can use "%" as a wildcard character. |
<b>Returns:</b>
[BooleanExpression](./firestore_pipelines.booleanexpression.md#booleanexpression_class)
A new `Expression` representing the 'like' comparison.
### Example
```typescript
// Check if the 'title' field contains the word "guide" (case-sensitive)
field("title").like("%guide%");
```
## Expression.like()
Creates an expression that performs a case-sensitive string comparison.
<b>Signature:</b>
```typescript
like(pattern: Expression): BooleanExpression;
```
#### Parameters
| Parameter | Type | Description |
| --- | --- | --- |
| pattern | [Expression](./firestore_pipelines.expression.md#expression_class) | The pattern to search for. You can use "%" as a wildcard character. |
<b>Returns:</b>
[BooleanExpression](./firestore_pipelines.booleanexpression.md#booleanexpression_class)
A new `Expression` representing the 'like' comparison.
### Example
```typescript
// Check if the 'title' field contains the word "guide" (case-sensitive)
field("title").like("%guide%");
```
## Expression.ln()
Creates an expression that computes the natural logarithm of a numeric value.
<b>Signature:</b>
```typescript
ln(): FunctionExpression;
```
<b>Returns:</b>
[FunctionExpression](./firestore_pipelines.functionexpression.md#functionexpression_class)
A new [Expression](./firestore_pipelines.expression.md#expression_class) representing the natural logarithm of the numeric value.
### Example
```typescript
// Compute the natural logarithm of the 'value' field.
field("value").ln();
```
## Expression.log10()
Creates an expression that computes the base-10 logarithm of a numeric value.
<b>Signature:</b>
```typescript
log10(): FunctionExpression;
```
<b>Returns:</b>
[FunctionExpression](./firestore_pipelines.functionexpression.md#functionexpression_class)
A new [Expression](./firestore_pipelines.expression.md#expression_class) representing the base-10 logarithm of the numeric value.
### Example
```typescript
// Compute the base-10 logarithm of the 'value' field.
field("value").log10();
```
## Expression.logicalMaximum()
Creates an expression that returns the larger value between this expression and another expression, based on Firestore's value type ordering.
<b>Signature:</b>
```typescript
logicalMaximum(second: Expression | unknown, ...others: Array<Expression | unknown>): FunctionExpression;
```
#### Parameters
| Parameter | Type | Description |
| --- | --- | --- |
| second | [Expression](./firestore_pipelines.expression.md#expression_class) \| unknown | The second expression or literal to compare with. |
| others | Array&lt;[Expression](./firestore_pipelines.expression.md#expression_class) \| unknown&gt; | Optional additional expressions or literals to compare with. |
<b>Returns:</b>
[FunctionExpression](./firestore_pipelines.functionexpression.md#functionexpression_class)
A new [Expression](./firestore_pipelines.expression.md#expression_class) representing the logical maximum operation.
### Example
```typescript
// Returns the larger value between the 'timestamp' field and the current timestamp.
field("timestamp").logicalMaximum(currentTimestamp());
```
## Expression.logicalMinimum()
Creates an expression that returns the smaller value between this expression and another expression, based on Firestore's value type ordering.
<b>Signature:</b>
```typescript
logicalMinimum(second: Expression | unknown, ...others: Array<Expression | unknown>): FunctionExpression;
```
#### Parameters
| Parameter | Type | Description |
| --- | --- | --- |
| second | [Expression](./firestore_pipelines.expression.md#expression_class) \| unknown | The second expression or literal to compare with. |
| others | Array&lt;[Expression](./firestore_pipelines.expression.md#expression_class) \| unknown&gt; | Optional additional expressions or literals to compare with. |
<b>Returns:</b>
[FunctionExpression](./firestore_pipelines.functionexpression.md#functionexpression_class)
A new [Expression](./firestore_pipelines.expression.md#expression_class) representing the logical minimum operation.
### Example
```typescript
// Returns the smaller value between the 'timestamp' field and the current timestamp.
field("timestamp").logicalMinimum(currentTimestamp());
```
## Expression.ltrim()
Trims whitespace or a specified set of characters/bytes from the beginning of a string or byte array.
<b>Signature:</b>
```typescript
ltrim(valueToTrim?: string | Expression | Bytes): FunctionExpression;
```
#### Parameters
| Parameter | Type | Description |
| --- | --- | --- |
| valueToTrim | string \| [Expression](./firestore_pipelines.expression.md#expression_class) \| [Bytes](./firestore_.bytes.md#bytes_class) | Optional. A string or byte array containing the characters/bytes to trim. If not specified, whitespace will be trimmed. |
<b>Returns:</b>
[FunctionExpression](./firestore_pipelines.functionexpression.md#functionexpression_class)
A new `Expression` representing the trimmed string.
### Example
```typescript
// Trim whitespace from the beginning of the 'userInput' field
field("userInput").ltrim();
// Trim quotes from the beginning of the 'userInput' field
field("userInput").ltrim('"');
```
## Expression.mapEntries()
Creates an expression that returns the entries of a map as an array of maps, where each map contains a `"k"` property for the key and a `"v"` property for the value. For example: `[{ k: "key1", v: "value1" }, ...]`<!-- -->.
<b>Signature:</b>
```typescript
mapEntries(): FunctionExpression;
```
<b>Returns:</b>
[FunctionExpression](./firestore_pipelines.functionexpression.md#functionexpression_class)
A new `Expression` representing the entries of the map.
### Example
```typescript
// Get the entries of the 'address' map
field("address").mapEntries();
```
## Expression.mapGet()
Accesses a value from a map (object) field using the provided key.
<b>Signature:</b>
```typescript
mapGet(subfield: string): FunctionExpression;
```
#### Parameters
| Parameter | Type | Description |
| --- | --- | --- |
| subfield | string | The key to access in the map. |
<b>Returns:</b>
[FunctionExpression](./firestore_pipelines.functionexpression.md#functionexpression_class)
A new `Expression` representing the value associated with the given key in the map.
### Example
```typescript
// Get the 'city' value from the 'address' map field
field("address").mapGet("city");
```
## Expression.mapKeys()
Creates an expression that returns the keys of a map.
While the backend generally preserves insertion order, relying on the order of the output array is not guaranteed and should be avoided.
<b>Signature:</b>
```typescript
mapKeys(): FunctionExpression;
```
<b>Returns:</b>
[FunctionExpression](./firestore_pipelines.functionexpression.md#functionexpression_class)
A new `Expression` representing the keys of the map.
### Example
```typescript
// Get the keys of the 'address' map
field("address").mapKeys();
```
## Expression.mapMerge()
Creates an expression that merges multiple map values.
<b>Signature:</b>
```typescript
mapMerge(secondMap: Record<string, unknown> | Expression, ...otherMaps: Array<Record<string, unknown> | Expression>): FunctionExpression;
```
#### Parameters
| Parameter | Type | Description |
| --- | --- | --- |
| secondMap | Record&lt;string, unknown&gt; \| [Expression](./firestore_pipelines.expression.md#expression_class) | A required second map to merge. Represented as a literal or an expression that returns a map. |
| otherMaps | Array&lt;Record&lt;string, unknown&gt; \| [Expression](./firestore_pipelines.expression.md#expression_class)<!-- -->&gt; | Optional additional maps to merge. Each map is represented as a literal or an expression that returns a map. |
<b>Returns:</b>
[FunctionExpression](./firestore_pipelines.functionexpression.md#functionexpression_class)
A new [Expression](./firestore_pipelines.expression.md#expression_class) representing the 'mapMerge' operation.
### Example
```
// Merges the map in the settings field with, a map literal, and a map in
// that is conditionally returned by another expression
field('settings').mapMerge({ enabled: true }, conditional(field('isAdmin'), { admin: true}, {})
```
## Expression.mapRemove()
Creates an expression that removes a key from the map produced by evaluating this expression.
<b>Signature:</b>
```typescript
mapRemove(key: string): FunctionExpression;
```
#### Parameters
| Parameter | Type | Description |
| --- | --- | --- |
| key | string | The name of the key to remove from the input map. |
<b>Returns:</b>
[FunctionExpression](./firestore_pipelines.functionexpression.md#functionexpression_class)
A new [Expression](./firestore_pipelines.expression.md#expression_class) representing the 'mapRemove' operation.
### Example
```
// Removes the key 'baz' from the input map.
map({foo: 'bar', baz: true}).mapRemove('baz');
```
## Expression.mapRemove()
Creates an expression that removes a key from the map produced by evaluating this expression.
<b>Signature:</b>
```typescript
mapRemove(keyExpr: Expression): FunctionExpression;
```
#### Parameters
| Parameter | Type | Description |
| --- | --- | --- |
| keyExpr | [Expression](./firestore_pipelines.expression.md#expression_class) | An expression that produces the name of the key to remove from the input map. |
<b>Returns:</b>
[FunctionExpression](./firestore_pipelines.functionexpression.md#functionexpression_class)
A new [Expression](./firestore_pipelines.expression.md#expression_class) representing the 'mapRemove' operation.
### Example
```
// Removes the key 'baz' from the input map.
map({foo: 'bar', baz: true}).mapRemove(constant('baz'));
@example
```
## Expression.mapSet()
Creates an expression that returns a new map with the specified entries added or updated.
Note that `mapSet` only performs shallow updates to the map. Setting a value to `null` will retain the key with a `null` value. To remove a key entirely, use `mapRemove`<!-- -->.
<b>Signature:</b>
```typescript
mapSet(key: string | Expression, value: unknown, ...moreKeyValues: unknown[]): FunctionExpression;
```
#### Parameters
| Parameter | Type | Description |
| --- | --- | --- |
| key | string \| [Expression](./firestore_pipelines.expression.md#expression_class) | The key to set. Must be a string or a constant string expression. |
| value | unknown | The value to set. |
| moreKeyValues | unknown\[\] | Additional key-value pairs to set. |
<b>Returns:</b>
[FunctionExpression](./firestore_pipelines.functionexpression.md#functionexpression_class)
A new `Expression` representing the map with the entries set.
### Example
```typescript
// Set the 'city' to "San Francisco" in the 'address' map
field("address").mapSet("city", "San Francisco");
```
## Expression.mapValues()
Creates an expression that returns the values of a map.
While the backend generally preserves insertion order, relying on the order of the output array is not guaranteed and should be avoided.
<b>Signature:</b>
```typescript
mapValues(): FunctionExpression;
```
<b>Returns:</b>
[FunctionExpression](./firestore_pipelines.functionexpression.md#functionexpression_class)
A new `Expression` representing the values of the map.
### Example
```typescript
// Get the values of the 'address' map
field("address").mapValues();
```
## Expression.maximum()
Creates an aggregation that finds the maximum value of a field across multiple stage inputs.
<b>Signature:</b>
```typescript
maximum(): AggregateFunction;
```
<b>Returns:</b>
[AggregateFunction](./firestore_pipelines.aggregatefunction.md#aggregatefunction_class)
A new `AggregateFunction` representing the 'maximum' aggregation.
### Example
```typescript
// Find the highest score in a leaderboard
field("score").maximum().as("highestScore");
```
## Expression.minimum()
Creates an aggregation that finds the minimum value of a field across multiple stage inputs.
<b>Signature:</b>
```typescript
minimum(): AggregateFunction;
```
<b>Returns:</b>
[AggregateFunction](./firestore_pipelines.aggregatefunction.md#aggregatefunction_class)
A new `AggregateFunction` representing the 'minimum' aggregation.
### Example
```typescript
// Find the lowest price of all products
field("price").minimum().as("lowestPrice");
```
## Expression.mod()
Creates an expression that calculates the modulo (remainder) of dividing this expression by another expression.
<b>Signature:</b>
```typescript
mod(expression: Expression): FunctionExpression;
```
#### Parameters
| Parameter | Type | Description |
| --- | --- | --- |
| expression | [Expression](./firestore_pipelines.expression.md#expression_class) | The expression to divide by. |
<b>Returns:</b>
[FunctionExpression](./firestore_pipelines.functionexpression.md#functionexpression_class)
A new `Expression` representing the modulo operation.
### Example
```typescript
// Calculate the remainder of dividing the 'value' field by the 'divisor' field
field("value").mod(field("divisor"));
```
## Expression.mod()
Creates an expression that calculates the modulo (remainder) of dividing this expression by a constant value.
<b>Signature:</b>
```typescript
mod(value: number): FunctionExpression;
```
#### Parameters
| Parameter | Type | Description |
| --- | --- | --- |
| value | number | The constant value to divide by. |
<b>Returns:</b>
[FunctionExpression](./firestore_pipelines.functionexpression.md#functionexpression_class)
A new `Expression` representing the modulo operation.
### Example
```typescript
// Calculate the remainder of dividing the 'value' field by 10
field("value").mod(10);
```
## Expression.multiply()
Creates an expression that multiplies this expression by another expression.
<b>Signature:</b>
```typescript
multiply(second: Expression | number): FunctionExpression;
```
#### Parameters
| Parameter | Type | Description |
| --- | --- | --- |
| second | [Expression](./firestore_pipelines.expression.md#expression_class) \| number | The second expression or literal to multiply by. |
<b>Returns:</b>
[FunctionExpression](./firestore_pipelines.functionexpression.md#functionexpression_class)
A new `Expression` representing the multiplication operation.
### Example
```typescript
// Multiply the 'quantity' field by the 'price' field
field("quantity").multiply(field("price"));
```
## Expression.notEqual()
Creates an expression that checks if this expression is not equal to another expression.
<b>Signature:</b>
```typescript
notEqual(expression: Expression): BooleanExpression;
```
#### Parameters
| Parameter | Type | Description |
| --- | --- | --- |
| expression | [Expression](./firestore_pipelines.expression.md#expression_class) | The expression to compare for inequality. |
<b>Returns:</b>
[BooleanExpression](./firestore_pipelines.booleanexpression.md#booleanexpression_class)
A new `Expression` representing the inequality comparison.
### Example
```typescript
// Check if the 'status' field is not equal to "completed"
field("status").notEqual("completed");
```
## Expression.notEqual()
Creates an expression that checks if this expression is not equal to a constant value.
<b>Signature:</b>
```typescript
notEqual(value: unknown): BooleanExpression;
```
#### Parameters
| Parameter | Type | Description |
| --- | --- | --- |
| value | unknown | The constant value to compare for inequality. |
<b>Returns:</b>
[BooleanExpression](./firestore_pipelines.booleanexpression.md#booleanexpression_class)
A new `Expression` representing the inequality comparison.
### Example
```typescript
// Check if the 'country' field is not equal to "USA"
field("country").notEqual("USA");
```
## Expression.notEqualAny()
Creates an expression that checks if this expression is not equal to any of the provided values or expressions.
<b>Signature:</b>
```typescript
notEqualAny(values: Array<Expression | unknown>): BooleanExpression;
```
#### Parameters
| Parameter | Type | Description |
| --- | --- | --- |
| values | Array&lt;[Expression](./firestore_pipelines.expression.md#expression_class) \| unknown&gt; | The values or expressions to check against. |
<b>Returns:</b>
[BooleanExpression](./firestore_pipelines.booleanexpression.md#booleanexpression_class)
A new `Expression` representing the 'notEqualAny' comparison.
### Example
```typescript
// Check if the 'status' field is neither "pending" nor the value of 'rejectedStatus'
field("status").notEqualAny(["pending", field("rejectedStatus")]);
```
## Expression.notEqualAny()
Creates an expression that checks if this expression is not equal to any of the values in the evaluated expression.
<b>Signature:</b>
```typescript
notEqualAny(arrayExpression: Expression): BooleanExpression;
```
#### Parameters
| Parameter | Type | Description |
| --- | --- | --- |
| arrayExpression | [Expression](./firestore_pipelines.expression.md#expression_class) | The values or expressions to check against. |
<b>Returns:</b>
[BooleanExpression](./firestore_pipelines.booleanexpression.md#booleanexpression_class)
A new `Expression` representing the 'notEqualAny' comparison.
### Example
```typescript
// Check if the 'status' field is not equal to any value in the field 'rejectedStatuses'
field("status").notEqualAny(field('rejectedStatuses'));
```
## Expression.parent()
Creates an expression that returns the parent document reference of a document reference.
<b>Signature:</b>
```typescript
parent(): FunctionExpression;
```
<b>Returns:</b>
[FunctionExpression](./firestore_pipelines.functionexpression.md#functionexpression_class)
A new [Expression](./firestore_pipelines.expression.md#expression_class) representing the parent operation.
### Example
```typescript
// Get the parent document reference of a document reference.
field("__path__").parent();
```
## Expression.pow()
Creates an expression that returns the value of this expression raised to the power of another expression.
<b>Signature:</b>
```typescript
pow(exponent: Expression): FunctionExpression;
```
#### Parameters
| Parameter | Type | Description |
| --- | --- | --- |
| exponent | [Expression](./firestore_pipelines.expression.md#expression_class) | The expression to raise this expression to the power of. |
<b>Returns:</b>
[FunctionExpression](./firestore_pipelines.functionexpression.md#functionexpression_class)
A new `Expression` representing the power operation.
### Example
```typescript
// Raise the value of the 'base' field to the power of the 'exponent' field.
field("base").pow(field("exponent"));
```
## Expression.pow()
Creates an expression that returns the value of this expression raised to the power of a constant value.
<b>Signature:</b>
```typescript
pow(exponent: number): FunctionExpression;
```
#### Parameters
| Parameter | Type | Description |
| --- | --- | --- |
| exponent | number | The constant value to raise this expression to the power of. |
<b>Returns:</b>
[FunctionExpression](./firestore_pipelines.functionexpression.md#functionexpression_class)
A new `Expression` representing the power operation.
### Example
```typescript
// Raise the value of the 'base' field to the power of 2.
field("base").pow(2);
```
## Expression.regexContains()
Creates an expression that checks if a string contains a specified regular expression as a substring.
<b>Signature:</b>
```typescript
regexContains(pattern: string): BooleanExpression;
```
#### Parameters
| Parameter | Type | Description |
| --- | --- | --- |
| pattern | string | The regular expression to use for the search. |
<b>Returns:</b>
[BooleanExpression](./firestore_pipelines.booleanexpression.md#booleanexpression_class)
A new `Expression` representing the 'contains' comparison.
### Example
```typescript
// Check if the 'description' field contains "example" (case-insensitive)
field("description").regexContains("(?i)example");
```
## Expression.regexContains()
Creates an expression that checks if a string contains a specified regular expression as a substring.
<b>Signature:</b>
```typescript
regexContains(pattern: Expression): BooleanExpression;
```
#### Parameters
| Parameter | Type | Description |
| --- | --- | --- |
| pattern | [Expression](./firestore_pipelines.expression.md#expression_class) | The regular expression to use for the search. |
<b>Returns:</b>
[BooleanExpression](./firestore_pipelines.booleanexpression.md#booleanexpression_class)
A new `Expression` representing the 'contains' comparison.
### Example
```typescript
// Check if the 'description' field contains the regular expression stored in field 'regex'
field("description").regexContains(field("regex"));
```
## Expression.regexFind()
Creates an expression that returns the first substring of a string expression that matches a specified regular expression.
This expression uses the [RE2](https://github.com/google/re2/wiki/Syntax) regular expression syntax.
<b>Signature:</b>
```typescript
regexFind(pattern: string): FunctionExpression;
```
#### Parameters
| Parameter | Type | Description |
| --- | --- | --- |
| pattern | string | The regular expression to search for. |
<b>Returns:</b>
[FunctionExpression](./firestore_pipelines.functionexpression.md#functionexpression_class)
A new [Expression](./firestore_pipelines.expression.md#expression_class) representing the regular expression find function.
### Example
```typescript
// Extract the domain from an email address
field("email").regexFind("@.+")
```
## Expression.regexFind()
Creates an expression that returns the first substring of a string expression that matches a specified regular expression.
This expression uses the [RE2](https://github.com/google/re2/wiki/Syntax) regular expression syntax.
<b>Signature:</b>
```typescript
regexFind(pattern: Expression): FunctionExpression;
```
#### Parameters
| Parameter | Type | Description |
| --- | --- | --- |
| pattern | [Expression](./firestore_pipelines.expression.md#expression_class) | The regular expression to search for. |
<b>Returns:</b>
[FunctionExpression](./firestore_pipelines.functionexpression.md#functionexpression_class)
A new [Expression](./firestore_pipelines.expression.md#expression_class) representing the regular expression find function.
### Example
```typescript
// Extract the domain from an email address
field("email").regexFind(field("domain"))
```
## Expression.regexFindAll()
Creates an expression that evaluates to a list of all substrings in this string expression that match a specified regular expression.
This expression uses the [RE2](https://github.com/google/re2/wiki/Syntax) regular expression syntax.
<b>Signature:</b>
```typescript
regexFindAll(pattern: string): FunctionExpression;
```
#### Parameters
| Parameter | Type | Description |
| --- | --- | --- |
| pattern | string | The regular expression to search for. |
<b>Returns:</b>
[FunctionExpression](./firestore_pipelines.functionexpression.md#functionexpression_class)
A new [Expression](./firestore_pipelines.expression.md#expression_class) that evaluates to an array of matched substrings.
### Example
```typescript
// Extract all hashtags from a post content field
field("content").regexFindAll("#[A-Za-z0-9_]+")
```
## Expression.regexFindAll()
Creates an expression that evaluates to a list of all substrings in this string expression that match a specified regular expression.
This expression uses the [RE2](https://github.com/google/re2/wiki/Syntax) regular expression syntax.
<b>Signature:</b>
```typescript
regexFindAll(pattern: Expression): FunctionExpression;
```
#### Parameters
| Parameter | Type | Description |
| --- | --- | --- |
| pattern | [Expression](./firestore_pipelines.expression.md#expression_class) | The regular expression to search for. |
<b>Returns:</b>
[FunctionExpression](./firestore_pipelines.functionexpression.md#functionexpression_class)
A new [Expression](./firestore_pipelines.expression.md#expression_class) that evaluates to an array of matched substrings.
### Example
```typescript
// Extract all names from a post content field
field("content").regexFindAll(field("names"))
```
## Expression.regexMatch()
Creates an expression that checks if a string matches a specified regular expression.
<b>Signature:</b>
```typescript
regexMatch(pattern: string): BooleanExpression;
```
#### Parameters
| Parameter | Type | Description |
| --- | --- | --- |
| pattern | string | The regular expression to use for the match. |
<b>Returns:</b>
[BooleanExpression](./firestore_pipelines.booleanexpression.md#booleanexpression_class)
A new `Expression` representing the regular expression match.
### Example
```typescript
// Check if the 'email' field matches a valid email pattern
field("email").regexMatch("[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\\.[A-Za-z]{2,}");
```
## Expression.regexMatch()
Creates an expression that checks if a string matches a specified regular expression.
<b>Signature:</b>
```typescript
regexMatch(pattern: Expression): BooleanExpression;
```
#### Parameters
| Parameter | Type | Description |
| --- | --- | --- |
| pattern | [Expression](./firestore_pipelines.expression.md#expression_class) | The regular expression to use for the match. |
<b>Returns:</b>
[BooleanExpression](./firestore_pipelines.booleanexpression.md#booleanexpression_class)
A new `Expression` representing the regular expression match.
### Example
```typescript
// Check if the 'email' field matches a regular expression stored in field 'regex'
field("email").regexMatch(field("regex"));
```
## Expression.reverse()
Creates an expression that reverses this string expression.
<b>Signature:</b>
```typescript
reverse(): FunctionExpression;
```
<b>Returns:</b>
[FunctionExpression](./firestore_pipelines.functionexpression.md#functionexpression_class)
A new [Expression](./firestore_pipelines.expression.md#expression_class) representing the reversed string.
### Example
```typescript
// Reverse the value of the 'myString' field.
field("myString").reverse();
```
## Expression.round()
Creates an expression that rounds a numeric value to the nearest whole number.
<b>Signature:</b>
```typescript
round(): FunctionExpression;
```
<b>Returns:</b>
[FunctionExpression](./firestore_pipelines.functionexpression.md#functionexpression_class)
A new `Expression` representing the rounded value.
### Example
```typescript
// Round the value of the 'price' field.
field("price").round();
```
## Expression.round()
Creates an expression that rounds a numeric value to the specified number of decimal places.
<b>Signature:</b>
```typescript
round(decimalPlaces: number): FunctionExpression;
```
#### Parameters
| Parameter | Type | Description |
| --- | --- | --- |
| decimalPlaces | number | A constant specifying the rounding precision in decimal places. |
<b>Returns:</b>
[FunctionExpression](./firestore_pipelines.functionexpression.md#functionexpression_class)
A new `Expression` representing the rounded value.
### Example
```typescript
// Round the value of the 'price' field to two decimal places.
field("price").round(2);
```
## Expression.round()
Creates an expression that rounds a numeric value to the specified number of decimal places.
<b>Signature:</b>
```typescript
round(decimalPlaces: Expression): FunctionExpression;
```
#### Parameters
| Parameter | Type | Description |
| --- | --- | --- |
| decimalPlaces | [Expression](./firestore_pipelines.expression.md#expression_class) | An expression specifying the rounding precision in decimal places. |
<b>Returns:</b>
[FunctionExpression](./firestore_pipelines.functionexpression.md#functionexpression_class)
A new `Expression` representing the rounded value.
### Example
```typescript
// Round the value of the 'price' field to two decimal places.
field("price").round(constant(2));
```
## Expression.rtrim()
Trims whitespace or a specified set of characters/bytes from the end of a string or byte array.
<b>Signature:</b>
```typescript
rtrim(valueToTrim?: string | Expression | Bytes): FunctionExpression;
```
#### Parameters
| Parameter | Type | Description |
| --- | --- | --- |
| valueToTrim | string \| [Expression](./firestore_pipelines.expression.md#expression_class) \| [Bytes](./firestore_.bytes.md#bytes_class) | Optional. A string or byte array containing the characters/bytes to trim. If not specified, whitespace will be trimmed. |
<b>Returns:</b>
[FunctionExpression](./firestore_pipelines.functionexpression.md#functionexpression_class)
A new `Expression` representing the trimmed string or byte array.
### Example
```typescript
// Trim whitespace from the end of the 'userInput' field
field("userInput").rtrim();
// Trim quotes from the end of the 'userInput' field
field("userInput").rtrim('"');
```
## Expression.split()
Creates an expression that splits the result of this expression into an array of substrings based on the provided delimiter.
<b>Signature:</b>
```typescript
split(delimiter: string): FunctionExpression;
```
#### Parameters
| Parameter | Type | Description |
| --- | --- | --- |
| delimiter | string | |
<b>Returns:</b>
[FunctionExpression](./firestore_pipelines.functionexpression.md#functionexpression_class)
A new [Expression](./firestore_pipelines.expression.md#expression_class) representing the split function.
### Example
```typescript
// Split the 'scoresCsv' field on delimiter ','
field('scoresCsv').split(',')
```
## Expression.split()
Creates an expression that splits the result of this expression into an array of substrings based on the provided delimiter.
<b>Signature:</b>
```typescript
split(delimiter: Expression): FunctionExpression;
```
#### Parameters
| Parameter | Type | Description |
| --- | --- | --- |
| delimiter | [Expression](./firestore_pipelines.expression.md#expression_class) | |
<b>Returns:</b>
[FunctionExpression](./firestore_pipelines.functionexpression.md#functionexpression_class)
A new [Expression](./firestore_pipelines.expression.md#expression_class) representing the split function.
### Example
```typescript
// Split the 'scores' field on delimiter ',' or ':' depending on the stored format
field('scores').split(conditional(field('format').equal('csv'), constant(','), constant(':')))
```
## Expression.sqrt()
Creates an expression that computes the square root of a numeric value.
<b>Signature:</b>
```typescript
sqrt(): FunctionExpression;
```
<b>Returns:</b>
[FunctionExpression](./firestore_pipelines.functionexpression.md#functionexpression_class)
A new [Expression](./firestore_pipelines.expression.md#expression_class) representing the square root of the numeric value.
### Example
```typescript
// Compute the square root of the 'value' field.
field("value").sqrt();
```
## Expression.startsWith()
Creates an expression that checks if a string starts with a given prefix.
<b>Signature:</b>
```typescript
startsWith(prefix: string): BooleanExpression;
```
#### Parameters
| Parameter | Type | Description |
| --- | --- | --- |
| prefix | string | The prefix to check for. |
<b>Returns:</b>
[BooleanExpression](./firestore_pipelines.booleanexpression.md#booleanexpression_class)
A new `Expression` representing the 'starts with' comparison.
### Example
```typescript
// Check if the 'name' field starts with "Mr."
field("name").startsWith("Mr.");
```
## Expression.startsWith()
Creates an expression that checks if a string starts with a given prefix (represented as an expression).
<b>Signature:</b>
```typescript
startsWith(prefix: Expression): BooleanExpression;
```
#### Parameters
| Parameter | Type | Description |
| --- | --- | --- |
| prefix | [Expression](./firestore_pipelines.expression.md#expression_class) | The prefix expression to check for. |
<b>Returns:</b>
[BooleanExpression](./firestore_pipelines.booleanexpression.md#booleanexpression_class)
A new `Expression` representing the 'starts with' comparison.
### Example
```typescript
// Check if the 'fullName' field starts with the value of the 'firstName' field
field("fullName").startsWith(field("firstName"));
```
## Expression.stringConcat()
Creates an expression that concatenates string expressions together.
<b>Signature:</b>
```typescript
stringConcat(secondString: Expression | string, ...otherStrings: Array<Expression | string>): FunctionExpression;
```
#### Parameters
| Parameter | Type | Description |
| --- | --- | --- |
| secondString | [Expression](./firestore_pipelines.expression.md#expression_class) \| string | The additional expression or string literal to concatenate. |
| otherStrings | Array&lt;[Expression](./firestore_pipelines.expression.md#expression_class) \| string&gt; | Optional additional expressions or string literals to concatenate. |
<b>Returns:</b>
[FunctionExpression](./firestore_pipelines.functionexpression.md#functionexpression_class)
A new `Expression` representing the concatenated string.
### Example
```typescript
// Combine the 'firstName', " ", and 'lastName' fields into a single string
field("firstName").stringConcat(constant(" "), field("lastName"));
```
## Expression.stringContains()
Creates an expression that checks if a string contains a specified substring.
<b>Signature:</b>
```typescript
stringContains(substring: string): BooleanExpression;
```
#### Parameters
| Parameter | Type | Description |
| --- | --- | --- |
| substring | string | The substring to search for. |
<b>Returns:</b>
[BooleanExpression](./firestore_pipelines.booleanexpression.md#booleanexpression_class)
A new `Expression` representing the 'contains' comparison.
### Example
```typescript
// Check if the 'description' field contains "example".
field("description").stringContains("example");
```
## Expression.stringContains()
Creates an expression that checks if a string contains the string represented by another expression.
<b>Signature:</b>
```typescript
stringContains(expr: Expression): BooleanExpression;
```
#### Parameters
| Parameter | Type | Description |
| --- | --- | --- |
| expr | [Expression](./firestore_pipelines.expression.md#expression_class) | The expression representing the substring to search for. |
<b>Returns:</b>
[BooleanExpression](./firestore_pipelines.booleanexpression.md#booleanexpression_class)
A new `Expression` representing the 'contains' comparison.
### Example
```typescript
// Check if the 'description' field contains the value of the 'keyword' field.
field("description").stringContains(field("keyword"));
```
## Expression.stringIndexOf()
Creates an expression that finds the index of the first occurrence of a substring or byte sequence.
<b>Signature:</b>
```typescript
stringIndexOf(search: string | Expression | Bytes): FunctionExpression;
```
#### Parameters
| Parameter | Type | Description |
| --- | --- | --- |
| search | string \| [Expression](./firestore_pipelines.expression.md#expression_class) \| [Bytes](./firestore_.bytes.md#bytes_class) | The substring or byte sequence to search for. |
<b>Returns:</b>
[FunctionExpression](./firestore_pipelines.functionexpression.md#functionexpression_class)
A new `Expression` representing the index of the first occurrence.
### Example
```typescript
// Find the index of "foo" in the 'text' field
field("text").stringIndexOf("foo");
```
## Expression.stringRepeat()
Creates an expression that repeats a string or byte array a specified number of times.
<b>Signature:</b>
```typescript
stringRepeat(repetitions: number | Expression): FunctionExpression;
```
#### Parameters
| Parameter | Type | Description |
| --- | --- | --- |
| repetitions | number \| [Expression](./firestore_pipelines.expression.md#expression_class) | The number of times to repeat the string or byte array. |
<b>Returns:</b>
[FunctionExpression](./firestore_pipelines.functionexpression.md#functionexpression_class)
A new `Expression` representing the repeated string or byte array.
### Example
```typescript
// Repeat the 'label' field 3 times
field("label").stringRepeat(3);
```
## Expression.stringReplaceAll()
Creates an expression that replaces all occurrences of a substring or byte sequence with a replacement.
<b>Signature:</b>
```typescript
stringReplaceAll(find: string | Expression | Bytes, replacement: string | Expression | Bytes): FunctionExpression;
```
#### Parameters
| Parameter | Type | Description |
| --- | --- | --- |
| find | string \| [Expression](./firestore_pipelines.expression.md#expression_class) \| [Bytes](./firestore_.bytes.md#bytes_class) | The substring or byte sequence to search for. |
| replacement | string \| [Expression](./firestore_pipelines.expression.md#expression_class) \| [Bytes](./firestore_.bytes.md#bytes_class) | The replacement string or byte sequence. |
<b>Returns:</b>
[FunctionExpression](./firestore_pipelines.functionexpression.md#functionexpression_class)
A new `Expression` representing the string or byte array with replacements.
### Example
```typescript
// Replace all occurrences of "foo" with "bar" in the 'text' field
field("text").stringReplaceAll("foo", "bar");
```
## Expression.stringReplaceOne()
Creates an expression that replaces the first occurrence of a substring or byte sequence with a replacement.
<b>Signature:</b>
```typescript
stringReplaceOne(find: string | Expression | Bytes, replacement: string | Expression | Bytes): FunctionExpression;
```
#### Parameters
| Parameter | Type | Description |
| --- | --- | --- |
| find | string \| [Expression](./firestore_pipelines.expression.md#expression_class) \| [Bytes](./firestore_.bytes.md#bytes_class) | The substring or byte sequence to search for. |
| replacement | string \| [Expression](./firestore_pipelines.expression.md#expression_class) \| [Bytes](./firestore_.bytes.md#bytes_class) | The replacement string or byte sequence. |
<b>Returns:</b>
[FunctionExpression](./firestore_pipelines.functionexpression.md#functionexpression_class)
A new `Expression` representing the string or byte array with the replacement.
### Example
```typescript
// Replace the first occurrence of "foo" with "bar" in the 'text' field
field("text").stringReplaceOne("foo", "bar");
```
## Expression.stringReverse()
Creates an expression that reverses a string.
<b>Signature:</b>
```typescript
stringReverse(): FunctionExpression;
```
<b>Returns:</b>
[FunctionExpression](./firestore_pipelines.functionexpression.md#functionexpression_class)
A new [Expression](./firestore_pipelines.expression.md#expression_class) representing the reversed string.
### Example
```typescript
// Reverse the value of the 'myString' field.
field("myString").stringReverse();
```
## Expression.substring()
Creates an expression that returns a substring of the results of this expression.
<b>Signature:</b>
```typescript
substring(position: number, length?: number): FunctionExpression;
```
#### Parameters
| Parameter | Type | Description |
| --- | --- | --- |
| position | number | Index of the first character of the substring. |
| length | number | Length of the substring. If not provided, the substring will end at the end of the input. |
<b>Returns:</b>
[FunctionExpression](./firestore_pipelines.functionexpression.md#functionexpression_class)
## Expression.substring()
Creates an expression that returns a substring of the results of this expression.
<b>Signature:</b>
```typescript
substring(position: Expression, length?: Expression): FunctionExpression;
```
#### Parameters
| Parameter | Type | Description |
| --- | --- | --- |
| position | [Expression](./firestore_pipelines.expression.md#expression_class) | An expression returning the index of the first character of the substring. |
| length | [Expression](./firestore_pipelines.expression.md#expression_class) | An expression returning the length of the substring. If not provided the substring will end at the end of the input. |
<b>Returns:</b>
[FunctionExpression](./firestore_pipelines.functionexpression.md#functionexpression_class)
## Expression.subtract()
Creates an expression that subtracts another expression from this expression.
<b>Signature:</b>
```typescript
subtract(subtrahend: Expression): FunctionExpression;
```
#### Parameters
| Parameter | Type | Description |
| --- | --- | --- |
| subtrahend | [Expression](./firestore_pipelines.expression.md#expression_class) | The expression to subtract from this expression. |
<b>Returns:</b>
[FunctionExpression](./firestore_pipelines.functionexpression.md#functionexpression_class)
A new `Expression` representing the subtraction operation.
### Example
```typescript
// Subtract the 'discount' field from the 'price' field
field("price").subtract(field("discount"));
```
## Expression.subtract()
Creates an expression that subtracts a constant value from this expression.
<b>Signature:</b>
```typescript
subtract(subtrahend: number): FunctionExpression;
```
#### Parameters
| Parameter | Type | Description |
| --- | --- | --- |
| subtrahend | number | The constant value to subtract. |
<b>Returns:</b>
[FunctionExpression](./firestore_pipelines.functionexpression.md#functionexpression_class)
A new `Expression` representing the subtraction operation.
### Example
```typescript
// Subtract 20 from the value of the 'total' field
field("total").subtract(20);
```
## Expression.sum()
Creates an aggregation that calculates the sum of a numeric field across multiple stage inputs.
<b>Signature:</b>
```typescript
sum(): AggregateFunction;
```
<b>Returns:</b>
[AggregateFunction](./firestore_pipelines.aggregatefunction.md#aggregatefunction_class)
A new `AggregateFunction` representing the 'sum' aggregation.
### Example
```typescript
// Calculate the total revenue from a set of orders
field("orderAmount").sum().as("totalRevenue");
```
## Expression.timestampAdd()
Creates an expression that adds a specified amount of time to this timestamp expression.
<b>Signature:</b>
```typescript
timestampAdd(unit: Expression, amount: Expression): FunctionExpression;
```
#### Parameters
| Parameter | Type | Description |
| --- | --- | --- |
| unit | [Expression](./firestore_pipelines.expression.md#expression_class) | The expression evaluates to unit of time, must be one of 'microsecond', 'millisecond', 'second', 'minute', 'hour', 'day'. |
| amount | [Expression](./firestore_pipelines.expression.md#expression_class) | The expression evaluates to amount of the unit. |
<b>Returns:</b>
[FunctionExpression](./firestore_pipelines.functionexpression.md#functionexpression_class)
A new [Expression](./firestore_pipelines.expression.md#expression_class) representing the resulting timestamp.
### Example
```typescript
// Add some duration determined by field 'unit' and 'amount' to the 'timestamp' field.
field("timestamp").timestampAdd(field("unit"), field("amount"));
```
## Expression.timestampAdd()
Creates an expression that adds a specified amount of time to this timestamp expression.
<b>Signature:</b>
```typescript
timestampAdd(unit: TimeUnit, amount: number): FunctionExpression;
```
#### Parameters
| Parameter | Type | Description |
| --- | --- | --- |
| unit | [TimeUnit](./firestore_pipelines.md#timeunit) | The unit of time to add (e.g., "day", "hour"). |
| amount | number | The amount of time to add. |
<b>Returns:</b>
[FunctionExpression](./firestore_pipelines.functionexpression.md#functionexpression_class)
A new [Expression](./firestore_pipelines.expression.md#expression_class) representing the resulting timestamp.
### Example
```typescript
// Add 1 day to the 'timestamp' field.
field("timestamp").timestampAdd("day", 1);
```
## Expression.timestampDiff()
Creates an expression that calculates the difference between this timestamp and another timestamp.
<b>Signature:</b>
```typescript
timestampDiff(start: Expression, unit: Expression): FunctionExpression;
```
#### Parameters
| Parameter | Type | Description |
| --- | --- | --- |
| start | [Expression](./firestore_pipelines.expression.md#expression_class) | The expression evaluating to the starting timestamp. |
| unit | [Expression](./firestore_pipelines.expression.md#expression_class) | The expression evaluates to a unit of time, must be one of 'microsecond', 'millisecond', 'second', 'minute', 'hour', 'day'. |
<b>Returns:</b>
[FunctionExpression](./firestore_pipelines.functionexpression.md#functionexpression_class)
A new [Expression](./firestore_pipelines.expression.md#expression_class) representing the difference as an integer.
### Example
```typescript
// Calculate the difference determined by fields 'startTime' and 'unit'.
field("endTime").timestampDiff(field("startTime"), field("unit"));
```
## Expression.timestampDiff()
Creates an expression that calculates the difference between this timestamp and another timestamp.
<b>Signature:</b>
```typescript
timestampDiff(start: string | Expression, unit: TimeUnit): FunctionExpression;
```
#### Parameters
| Parameter | Type | Description |
| --- | --- | --- |
| start | string \| [Expression](./firestore_pipelines.expression.md#expression_class) | The field name of the starting timestamp. |
| unit | [TimeUnit](./firestore_pipelines.md#timeunit) | The unit of time for the difference (e.g., "day", "hour"). |
<b>Returns:</b>
[FunctionExpression](./firestore_pipelines.functionexpression.md#functionexpression_class)
A new [Expression](./firestore_pipelines.expression.md#expression_class) representing the difference as an integer.
### Example
```typescript
// Calculate the difference in days between 'endTime' and 'startTime' fields.
field("endTime").timestampDiff("startTime", "day");
```
## Expression.timestampExtract()
Creates an expression that extracts a specified part from this timestamp expression.
<b>Signature:</b>
```typescript
timestampExtract(part: TimePart, timezone?: string | Expression): FunctionExpression;
```
#### Parameters
| Parameter | Type | Description |
| --- | --- | --- |
| part | [TimePart](./firestore_pipelines.md#timepart) | The part to extract from the timestamp (e.g., "year", "month", "day"). |
| timezone | string \| [Expression](./firestore_pipelines.expression.md#expression_class) | The timezone to use for extraction. Valid values are from the TZ database (e.g., "America/Los\_Angeles") or in the format "Etc/GMT-1." |
<b>Returns:</b>
[FunctionExpression](./firestore_pipelines.functionexpression.md#functionexpression_class)
A new [Expression](./firestore_pipelines.expression.md#expression_class) representing the extracted part as an integer.
### Example
```typescript
// Extract the year from the 'createdAt' field.
field('createdAt').timestampExtract('year')
```
## Expression.timestampExtract()
Creates an expression that extracts a specified part from this timestamp expression.
<b>Signature:</b>
```typescript
timestampExtract(part: Expression, timezone?: string | Expression): FunctionExpression;
```
#### Parameters
| Parameter | Type | Description |
| --- | --- | --- |
| part | [Expression](./firestore_pipelines.expression.md#expression_class) | The expression evaluating to the part to extract. |
| timezone | string \| [Expression](./firestore_pipelines.expression.md#expression_class) | The timezone to use for extraction. Valid values are from the TZ database (e.g., "America/Los\_Angeles") or in the format "Etc/GMT-1." |
<b>Returns:</b>
[FunctionExpression](./firestore_pipelines.functionexpression.md#functionexpression_class)
A new [Expression](./firestore_pipelines.expression.md#expression_class) representing the extracted part as an integer.
### Example
```typescript
// Extract the part specified by the field 'extractionPart' from 'createdAt'.
field('createdAt').timestampExtract(field('extractionPart'))
```
## Expression.timestampSubtract()
Creates an expression that subtracts a specified amount of time from this timestamp expression.
<b>Signature:</b>
```typescript
timestampSubtract(unit: Expression, amount: Expression): FunctionExpression;
```
#### Parameters
| Parameter | Type | Description |
| --- | --- | --- |
| unit | [Expression](./firestore_pipelines.expression.md#expression_class) | The expression evaluates to unit of time, must be one of 'microsecond', 'millisecond', 'second', 'minute', 'hour', 'day'. |
| amount | [Expression](./firestore_pipelines.expression.md#expression_class) | The expression evaluates to amount of the unit. |
<b>Returns:</b>
[FunctionExpression](./firestore_pipelines.functionexpression.md#functionexpression_class)
A new [Expression](./firestore_pipelines.expression.md#expression_class) representing the resulting timestamp.
### Example
```typescript
// Subtract some duration determined by field 'unit' and 'amount' from the 'timestamp' field.
field("timestamp").timestampSubtract(field("unit"), field("amount"));
```
## Expression.timestampSubtract()
Creates an expression that subtracts a specified amount of time from this timestamp expression.
<b>Signature:</b>
```typescript
timestampSubtract(unit: TimeUnit, amount: number): FunctionExpression;
```
#### Parameters
| Parameter | Type | Description |
| --- | --- | --- |
| unit | [TimeUnit](./firestore_pipelines.md#timeunit) | The unit of time to subtract (e.g., "day", "hour"). |
| amount | number | The amount of time to subtract. |
<b>Returns:</b>
[FunctionExpression](./firestore_pipelines.functionexpression.md#functionexpression_class)
A new [Expression](./firestore_pipelines.expression.md#expression_class) representing the resulting timestamp.
### Example
```typescript
// Subtract 1 day from the 'timestamp' field.
field("timestamp").timestampSubtract("day", 1);
```
## Expression.timestampToUnixMicros()
Creates an expression that converts this timestamp expression to the number of microseconds since the Unix epoch (1970-01-01 00:00:00 UTC).
<b>Signature:</b>
```typescript
timestampToUnixMicros(): FunctionExpression;
```
<b>Returns:</b>
[FunctionExpression](./firestore_pipelines.functionexpression.md#functionexpression_class)
A new [Expression](./firestore_pipelines.expression.md#expression_class) representing the number of microseconds since epoch.
### Example
```typescript
// Convert the 'timestamp' field to microseconds since epoch.
field("timestamp").timestampToUnixMicros();
```
## Expression.timestampToUnixMillis()
Creates an expression that converts this timestamp expression to the number of milliseconds since the Unix epoch (1970-01-01 00:00:00 UTC).
<b>Signature:</b>
```typescript
timestampToUnixMillis(): FunctionExpression;
```
<b>Returns:</b>
[FunctionExpression](./firestore_pipelines.functionexpression.md#functionexpression_class)
A new [Expression](./firestore_pipelines.expression.md#expression_class) representing the number of milliseconds since epoch.
### Example
```typescript
// Convert the 'timestamp' field to milliseconds since epoch.
field("timestamp").timestampToUnixMillis();
```
## Expression.timestampToUnixSeconds()
Creates an expression that converts this timestamp expression to the number of seconds since the Unix epoch (1970-01-01 00:00:00 UTC).
<b>Signature:</b>
```typescript
timestampToUnixSeconds(): FunctionExpression;
```
<b>Returns:</b>
[FunctionExpression](./firestore_pipelines.functionexpression.md#functionexpression_class)
A new [Expression](./firestore_pipelines.expression.md#expression_class) representing the number of seconds since epoch.
### Example
```typescript
// Convert the 'timestamp' field to seconds since epoch.
field("timestamp").timestampToUnixSeconds();
```
## Expression.timestampTruncate()
Creates an expression that truncates a timestamp to a specified granularity.
<b>Signature:</b>
```typescript
timestampTruncate(granularity: TimeGranularity, timezone?: string | Expression): FunctionExpression;
```
#### Parameters
| Parameter | Type | Description |
| --- | --- | --- |
| granularity | [TimeGranularity](./firestore_pipelines.md#timegranularity) | The granularity to truncate to. |
| timezone | string \| [Expression](./firestore_pipelines.expression.md#expression_class) | The timezone to use for truncation. Valid values are from the TZ database (e.g., "America/Los\_Angeles") or in the format "Etc/GMT-1". |
<b>Returns:</b>
[FunctionExpression](./firestore_pipelines.functionexpression.md#functionexpression_class)
A new [Expression](./firestore_pipelines.expression.md#expression_class) representing the truncated timestamp.
### Example
```typescript
// Truncate the 'createdAt' timestamp to the beginning of the day.
field('createdAt').timestampTruncate('day')
```
## Expression.timestampTruncate()
Creates an expression that truncates a timestamp to a specified granularity.
<b>Signature:</b>
```typescript
timestampTruncate(granularity: Expression, timezone?: string | Expression): FunctionExpression;
```
#### Parameters
| Parameter | Type | Description |
| --- | --- | --- |
| granularity | [Expression](./firestore_pipelines.expression.md#expression_class) | The granularity to truncate to. |
| timezone | string \| [Expression](./firestore_pipelines.expression.md#expression_class) | The timezone to use for truncation. Valid values are from the TZ database (e.g., "America/Los\_Angeles") or in the format "Etc/GMT-1". |
<b>Returns:</b>
[FunctionExpression](./firestore_pipelines.functionexpression.md#functionexpression_class)
A new [Expression](./firestore_pipelines.expression.md#expression_class) representing the truncated timestamp.
### Example
```typescript
// Truncate the 'createdAt' timestamp to the granularity specified in the field 'granularity'.
field('createdAt').timestampTruncate(field('granularity'))
```
## Expression.toLower()
Creates an expression that converts a string to lowercase.
<b>Signature:</b>
```typescript
toLower(): FunctionExpression;
```
<b>Returns:</b>
[FunctionExpression](./firestore_pipelines.functionexpression.md#functionexpression_class)
A new `Expression` representing the lowercase string.
### Example
```typescript
// Convert the 'name' field to lowercase
field("name").toLower();
```
## Expression.toUpper()
Creates an expression that converts a string to uppercase.
<b>Signature:</b>
```typescript
toUpper(): FunctionExpression;
```
<b>Returns:</b>
[FunctionExpression](./firestore_pipelines.functionexpression.md#functionexpression_class)
A new `Expression` representing the uppercase string.
### Example
```typescript
// Convert the 'title' field to uppercase
field("title").toUpper();
```
## Expression.trim()
Creates an expression that removes leading and trailing characters from a string or byte array.
<b>Signature:</b>
```typescript
trim(valueToTrim?: string | Expression | Bytes): FunctionExpression;
```
#### Parameters
| Parameter | Type | Description |
| --- | --- | --- |
| valueToTrim | string \| [Expression](./firestore_pipelines.expression.md#expression_class) \| [Bytes](./firestore_.bytes.md#bytes_class) | Optional This parameter is treated as a set of characters or bytes that will be trimmed from the input. If not specified, then whitespace will be trimmed. |
<b>Returns:</b>
[FunctionExpression](./firestore_pipelines.functionexpression.md#functionexpression_class)
A new `Expression` representing the trimmed string or byte array.
### Example
```typescript
// Trim whitespace from the 'userInput' field
field("userInput").trim();
// Trim quotes from the 'userInput' field
field("userInput").trim('"');
```
## Expression.trunc()
Creates an expression that truncates the numeric value to an integer.
<b>Signature:</b>
```typescript
trunc(): FunctionExpression;
```
<b>Returns:</b>
[FunctionExpression](./firestore_pipelines.functionexpression.md#functionexpression_class)
A new `Expression` representing the truncated value.
### Example
```typescript
// Truncate the 'rating' field
field("rating").trunc();
```
## Expression.trunc()
Creates an expression that truncates a numeric value to the specified number of decimal places.
<b>Signature:</b>
```typescript
trunc(decimalPlaces: number): FunctionExpression;
```
#### Parameters
| Parameter | Type | Description |
| --- | --- | --- |
| decimalPlaces | number | A constant specifying the truncation precision in decimal places. |
<b>Returns:</b>
[FunctionExpression](./firestore_pipelines.functionexpression.md#functionexpression_class)
A new `Expression` representing the truncated value.
### Example
```typescript
// Truncate the value of the 'rating' field to two decimal places.
field("rating").trunc(2);
```
## Expression.trunc()
Creates an expression that truncates a numeric value to the specified number of decimal places.
<b>Signature:</b>
```typescript
trunc(decimalPlaces: Expression): FunctionExpression;
```
#### Parameters
| Parameter | Type | Description |
| --- | --- | --- |
| decimalPlaces | [Expression](./firestore_pipelines.expression.md#expression_class) | An expression specifying the truncation precision in decimal places. |
<b>Returns:</b>
[FunctionExpression](./firestore_pipelines.functionexpression.md#functionexpression_class)
A new `Expression` representing the truncated value.
### Example
```typescript
// Truncate the value of the 'rating' field to two decimal places.
field("rating").trunc(constant(2));
```
## Expression.type()
Creates an expression that returns the data type of this expression's result, as a string.
This is evaluated on the backend. This means: 1. Generic typed elements (like `array<string>`<!-- -->) evaluate strictly to the primitive `'array'`<!-- -->. 2. Any custom `FirestoreDataConverter` mappings are ignored. 3. For numeric values, the backend does not yield the JavaScript `"number"` type; it evaluates precisely as `"int64"` or `"float64"`<!-- -->. 4. For date or timestamp objects, the backend evaluates to `"timestamp"`<!-- -->.
<b>Signature:</b>
```typescript
type(): FunctionExpression;
```
<b>Returns:</b>
[FunctionExpression](./firestore_pipelines.functionexpression.md#functionexpression_class)
A new `Expression` representing the data type.
### Example
```typescript
// Get the data type of the value in field 'title'
field('title').type()
```
## Expression.unixMicrosToTimestamp()
Creates an expression that interprets this expression as the number of microseconds since the Unix epoch (1970-01-01 00:00:00 UTC) and returns a timestamp.
<b>Signature:</b>
```typescript
unixMicrosToTimestamp(): FunctionExpression;
```
<b>Returns:</b>
[FunctionExpression](./firestore_pipelines.functionexpression.md#functionexpression_class)
A new [Expression](./firestore_pipelines.expression.md#expression_class) representing the timestamp.
### Example
```typescript
// Interpret the 'microseconds' field as microseconds since epoch.
field("microseconds").unixMicrosToTimestamp();
```
## Expression.unixMillisToTimestamp()
Creates an expression that interprets this expression as the number of milliseconds since the Unix epoch (1970-01-01 00:00:00 UTC) and returns a timestamp.
<b>Signature:</b>
```typescript
unixMillisToTimestamp(): FunctionExpression;
```
<b>Returns:</b>
[FunctionExpression](./firestore_pipelines.functionexpression.md#functionexpression_class)
A new [Expression](./firestore_pipelines.expression.md#expression_class) representing the timestamp.
### Example
```typescript
// Interpret the 'milliseconds' field as milliseconds since epoch.
field("milliseconds").unixMillisToTimestamp();
```
## Expression.unixSecondsToTimestamp()
Creates an expression that interprets this expression as the number of seconds since the Unix epoch (1970-01-01 00:00:00 UTC) and returns a timestamp.
<b>Signature:</b>
```typescript
unixSecondsToTimestamp(): FunctionExpression;
```
<b>Returns:</b>
[FunctionExpression](./firestore_pipelines.functionexpression.md#functionexpression_class)
A new [Expression](./firestore_pipelines.expression.md#expression_class) representing the timestamp.
### Example
```typescript
// Interpret the 'seconds' field as seconds since epoch.
field("seconds").unixSecondsToTimestamp();
```
## Expression.vectorLength()
Creates an expression that calculates the length (number of dimensions) of this Firestore Vector expression.
<b>Signature:</b>
```typescript
vectorLength(): FunctionExpression;
```
<b>Returns:</b>
[FunctionExpression](./firestore_pipelines.functionexpression.md#functionexpression_class)
A new [Expression](./firestore_pipelines.expression.md#expression_class) representing the length of the vector.
### Example
```typescript
// Get the vector length (dimension) of the field 'embedding'.
field("embedding").vectorLength();
```