Expression
public protocol Expression : SendableUndocumented
-
Default implementationasBoolean()
Casts the expression to a
BooleanExpression.Default Implementation
Declaration
Swift
func asBoolean() -> BooleanExpressionReturn Value
A
BooleanExpressionrepresenting the same expression. -
Default implementationas(_:)
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.
// Calculate total price and alias it "totalPrice" Field("price").multiply(Field("quantity")).as("totalPrice")Default Implementation
Declaration
Swift
func `as`(_ name: String) -> AliasedExpressionParameters
nameThe alias to assign to this expression.
Return Value
A new
AliasedExpressionwrapping this expression with the alias. -
Default implementationround()
Creates an expression that returns the value of self rounded to the nearest integer.
// Get the value of the "amount" field rounded to the nearest integer. Field("amount").round()Default Implementation
Declaration
Swift
func round() -> FunctionExpressionReturn Value
A new
FunctionExpressionrepresenting the rounded number. -
Default implementationsqrt()
Creates an expression that returns the square root of self.
// Get the square root of the "area" field. Field("area").sqrt()Default Implementation
Declaration
Swift
func sqrt() -> FunctionExpressionReturn Value
A new
FunctionExpressionrepresenting the square root of the number. -
Default implementationpow(_:)
Creates an expression that returns the value of self raised to the power of self.
Returns zero on underflow.
// Get the value of the "amount" field raised to the power of 2. Field("amount").pow(2)Default Implementation
Declaration
Swift
func pow(_ exponent: Sendable) -> FunctionExpressionParameters
exponentThe exponent to raise self to.
Return Value
A new
FunctionExpressionrepresenting the power of the number. -
Default implementationpow(_:)
Creates an expression that returns the value of self raised to the power of self.
Returns zero on underflow.
// Get the value of the "amount" field raised to the power of the "exponent" field. Field("amount").pow(Field("exponent"))Default Implementation
Declaration
Swift
func pow(_ exponent: Expression) -> FunctionExpressionParameters
exponentThe exponent to raise self to.
Return Value
A new
FunctionExpressionrepresenting the power of the number. -
Default implementationln()
Creates an expression that returns the natural logarithm of self.
// Get the natural logarithm of the "amount" field. Field("amount").ln()Default Implementation
Declaration
Swift
func ln() -> FunctionExpressionReturn Value
A new
FunctionExpressionrepresenting the natural logarithm of the number. -
Default implementationfloor()
Creates an expression that returns the largest numeric value that isn’t greater than self.
// Get the floor of the "amount" field. Field("amount").floor()Default Implementation
Declaration
Swift
func floor() -> FunctionExpressionReturn Value
A new
FunctionExpressionrepresenting the floor of the number. -
Default implementationexp()
Creates an expression that returns e to the power of self.
Returns zero on underflow and nil on overflow.
// Get the exp of the "amount" field. Field("amount").exp()Default Implementation
Declaration
Swift
func exp() -> FunctionExpressionReturn Value
A new
FunctionExpressionrepresenting the exp of the number. -
Default implementationceil()
Creates an expression that returns the smallest numeric value that isn’t less than the number.
// Get the ceiling of the "amount" field. Field("amount").ceil()Default Implementation
Declaration
Swift
func ceil() -> FunctionExpressionReturn Value
A new
FunctionExpressionrepresenting the ceiling of the number. -
Default implementationabs()
Creates an expression that returns the absolute value of the number.
// Get the absolute value of the "amount" field. Field("amount").abs()Default Implementation
Declaration
Swift
func abs() -> FunctionExpressionReturn Value
A new
FunctionExpressionrepresenting the absolute value of the number. -
Default implementationadd(_:)
Creates an expression that adds another expression to this expression. To add multiple expressions, chain calls to this method. Assumes
selfand the parameter evaluate to compatible types for addition (e.g., numbers, or string/array concatenation if supported by the specific “add” implementation).// Add the value of the "quantity" field and the "reserve" field. Field("quantity").add(Field("reserve")) // Add multiple numeric fields Field("subtotal").add(Field("tax")).add(Field("shipping"))Default Implementation
Declaration
Swift
func add(_ value: Expression) -> FunctionExpressionParameters
valueAn
Expressionto add.Return Value
A new
FunctionExpressionrepresenting the addition operation. -
Default implementationadd(_:)
Creates an expression that adds a literal value to this expression. To add multiple literals, chain calls to this method. Assumes
selfand the parameter evaluate to compatible types for addition.// Add 5 to the "count" field Field("count").add(5) // Add multiple literal numbers Field("score").add(10).add(20).add(-5)Default Implementation
Declaration
Swift
func add(_ value: Sendable) -> FunctionExpressionParameters
valueA
Sendableliteral value to add.Return Value
A new
FunctionExpressionrepresenting the addition operation. -
Default implementationsubtract(_:)
Creates an expression that subtracts another expression from this expression. Assumes
selfandotherevaluate to numeric types.// Subtract the "discount" field from the "price" field Field("price").subtract(Field("discount"))Default Implementation
Declaration
Swift
func subtract(_ other: Expression) -> FunctionExpressionParameters
otherThe
Expression(evaluating to a number) to subtract from this expression.Return Value
A new
FunctionExpressionrepresenting the subtraction operation. -
Default implementationsubtract(_:)
Creates an expression that subtracts a literal value from this expression. Assumes
selfevaluates to a numeric type.// Subtract 20 from the value of the "total" field Field("total").subtract(20)Default Implementation
Declaration
Swift
func subtract(_ other: Sendable) -> FunctionExpressionParameters
otherThe
Sendableliteral (numeric) value to subtract from this expression.Return Value
A new
FunctionExpressionrepresenting the subtraction operation. -
Default implementationmultiply(_:)
Creates an expression that multiplies this expression by another expression. To multiply multiple expressions, chain calls to this method. Assumes
selfand the parameter evaluate to numeric types.// Multiply the "quantity" field by the "price" field Field("quantity").multiply(Field("price")) // Multiply "rate" by "time" and "conversionFactor" fields Field("rate").multiply(Field("time")).multiply(Field("conversionFactor"))Default Implementation
Declaration
Swift
func multiply(_ value: Expression) -> FunctionExpressionParameters
valueAn
Expressionto multiply by.Return Value
A new
FunctionExpressionrepresenting the multiplication operation. -
Default implementationmultiply(_:)
Creates an expression that multiplies this expression by a literal value. To multiply multiple literals, chain calls to this method. Assumes
selfevaluates to a numeric type.// Multiply the "score" by 1.1 Field("score").multiply(1.1) // Multiply "base" by 2 and then by 3.0 Field("base").multiply(2).multiply(3.0)Default Implementation
Declaration
Swift
func multiply(_ value: Sendable) -> FunctionExpressionParameters
valueA
Sendableliteral value to multiply by.Return Value
A new
FunctionExpressionrepresenting the multiplication operation. -
Default implementationdivide(_:)
Creates an expression that divides this expression by another expression. Assumes
selfandotherevaluate to numeric types.// Divide the "total" field by the "count" field Field("total").divide(Field("count"))Default Implementation
Declaration
Swift
func divide(_ other: Expression) -> FunctionExpressionParameters
otherThe
Expression(evaluating to a number) to divide by.Return Value
A new
FunctionExpressionrepresenting the division operation. -
Default implementationdivide(_:)
Creates an expression that divides this expression by a literal value. Assumes
selfevaluates to a numeric type.// Divide the "value" field by 10 Field("value").divide(10)Default Implementation
Declaration
Swift
func divide(_ other: Sendable) -> FunctionExpressionParameters
otherThe
Sendableliteral (numeric) value to divide by.Return Value
A new
FunctionExpressionrepresenting the division operation. -
Default implementationmod(_:)
Creates an expression that calculates the modulo (remainder) of dividing this expression by another expression. Assumes
selfandotherevaluate to numeric types.// Calculate the remainder of dividing the "value" field by the "divisor" field Field("value").mod(Field("divisor"))Default Implementation
Declaration
Swift
func mod(_ other: Expression) -> FunctionExpressionParameters
otherThe
Expression(evaluating to a number) to use as the divisor.Return Value
A new
FunctionExpressionrepresenting the modulo operation. -
Default implementationmod(_:)
Creates an expression that calculates the modulo (remainder) of dividing this expression by a literal value. Assumes
selfevaluates to a numeric type.// Calculate the remainder of dividing the "value" field by 10 Field("value").mod(10)Default Implementation
Declaration
Swift
func mod(_ other: Sendable) -> FunctionExpressionParameters
otherThe
Sendableliteral (numeric) value to use as the divisor.Return Value
A new
FunctionExpressionrepresenting the modulo operation. -
Default implementationarrayReverse()
Creates an expression that returns the
inputwith elements in reverse order.// Reverse the "tags" array. Field("tags").arrayReverse()Default Implementation
Declaration
Swift
func arrayReverse() -> FunctionExpressionReturn Value
A new
FunctionExpressionrepresenting the reversed array. -
Default implementationarrayConcat(_:)
Creates an expression that concatenates an array expression (from
self) with one or more other array expressions. Assumesselfand all parameters evaluate to arrays.// Combine the "items" array with "otherItems" and "archiveItems" array fields. Field("items").arrayConcat(Field("otherItems"), Field("archiveItems"))Default Implementation
Declaration
Swift
func arrayConcat(_ arrays: [Expression]) -> FunctionExpressionParameters
arraysAn array of at least one
Expression(evaluating to an array) to concatenate.Return Value
A new
FunctionExpressionrepresenting the concatenated array. -
Default implementationarrayConcat(_:)
Creates an expression that concatenates an array expression (from
self) with one or more array literals. Assumesselfevaluates to an array.// Combine "tags" (an array field) with ["new", "featured"] and ["urgent"] Field("tags").arrayConcat(["new", "featured"], ["urgent"])Default Implementation
Declaration
Swift
func arrayConcat(_ arrays: [[Sendable]]) -> FunctionExpressionParameters
arraysAn array of at least one
Sendablevalues to concatenate.Return Value
A new
FunctionExpressionrepresenting the concatenated array. -
Default implementationarrayContains(_:)
Creates an expression that checks if an array (from
self) contains a specific element expression. Assumesselfevaluates to an array.// Check if "sizes" contains the value from "selectedSize" field Field("sizes").arrayContains(Field("selectedSize"))Default Implementation
Declaration
Swift
func arrayContains(_ element: Expression) -> BooleanExpressionParameters
elementThe
Expressionrepresenting the element to search for in the array.Return Value
A new
BooleanExprrepresenting the “array_contains” comparison. -
Default implementationarrayContains(_:)
Creates an expression that checks if an array (from
self) contains a specific literal element. Assumesselfevaluates to an array.// Check if "colors" array contains "red" Field("colors").arrayContains("red")Default Implementation
Declaration
Swift
func arrayContains(_ element: Sendable) -> BooleanExpressionParameters
elementThe
Sendableliteral element to search for in the array.Return Value
A new
BooleanExprrepresenting the “array_contains” comparison. -
Default implementationarrayContainsAll(_:)
Creates an expression that checks if an array (from
self) contains all the specified element expressions. Assumesselfevaluates to an array.// Check if "candidateSkills" contains all skills from "requiredSkill1" and "requiredSkill2" fields Field("candidateSkills").arrayContainsAll([Field("requiredSkill1"), Field("requiredSkill2")])Default Implementation
Declaration
Swift
func arrayContainsAll(_ values: [Expression]) -> BooleanExpressionParameters
valuesA list of
Expressionelements to check for in the array represented byself.Return Value
A new
BooleanExprrepresenting the “array_contains_all” comparison. -
Default implementationarrayContainsAll(_:)
Creates an expression that checks if an array (from
self) contains all the specified literal elements. Assumesselfevaluates to an array.// Check if "tags" contains both "urgent" and "review" Field("tags").arrayContainsAll(["urgent", "review"])Default Implementation
Declaration
Swift
func arrayContainsAll(_ values: [Sendable]) -> BooleanExpressionParameters
valuesAn array of at least one
Sendableelement to check for in the array.Return Value
A new
BooleanExprrepresenting the “array_contains_all” comparison. -
Default implementationarrayContainsAll(_:)
Creates an expression that checks if an array (from
self) contains all the specified element expressions. Assumesselfevaluates to an array.// Check if the "tags" array contains "foo", "bar", and "baz" Field("tags").arrayContainsAll(Constant(["foo", "bar", "baz"]))Default Implementation
Declaration
Swift
func arrayContainsAll(_ arrayExpression: Expression) -> BooleanExpressionParameters
valuesAn
Expressionelements evaluated to be array.Return Value
A new
BooleanExprrepresenting the “array_contains_all” comparison. -
Default implementationarrayContainsAny(_:)
Creates an expression that checks if an array (from
self) contains any of the specified element expressions. Assumesselfevaluates to an array.// Check if "userGroups" contains any group from "allowedGroup1" or "allowedGroup2" fields Field("userGroups").arrayContainsAny([Field("allowedGroup1"), Field("allowedGroup2")])Default Implementation
Declaration
Swift
func arrayContainsAny(_ values: [Expression]) -> BooleanExpressionParameters
valuesA list of
Expressionelements to check for in the array.Return Value
A new
BooleanExprrepresenting the “array_contains_any” comparison. -
Default implementationarrayContainsAny(_:)
Creates an expression that checks if an array (from
self) contains any of the specified literal elements. Assumesselfevaluates to an array.// Check if "categories" contains either "electronics" or "books" Field("categories").arrayContainsAny(["electronics", "books"])Default Implementation
Declaration
Swift
func arrayContainsAny(_ values: [Sendable]) -> BooleanExpressionParameters
valuesAn array of at least one
Sendableelement to check for in the array.Return Value
A new
BooleanExprrepresenting the “array_contains_any” comparison. -
Default implementationarrayContainsAny(_:)
Creates an expression that checks if an array (from
self) contains any of the specified element expressions. Assumesselfevaluates to an array.// Check if "groups" array contains any of the values from the "userGroup" field Field("groups").arrayContainsAny(Field("userGroup"))Default Implementation
Declaration
Swift
func arrayContainsAny(_ arrayExpression: Expression) -> BooleanExpressionParameters
arrayExpressionAn
Expressionelements evaluated to be array.Return Value
A new
BooleanExprrepresenting the “array_contains_any” comparison. -
Default implementationarrayLength()
Creates an expression that calculates the length of an array. Assumes
selfevaluates to an array.// Get the number of items in the "cart" array Field("cart").arrayLength()Default Implementation
Declaration
Swift
func arrayLength() -> FunctionExpressionReturn Value
A new
FunctionExpressionrepresenting the length of the array. -
Default implementationarrayGet(_:)
Creates an expression that accesses an element in an array (from
self) at the specified integer offset. A negative offset starts from the end. If the offset is out of bounds, an error may be returned during evaluation. Assumesselfevaluates to an array.// Return the value in the "tags" field array at index 1. Field("tags").arrayGet(1) // Return the last element in the "tags" field array. Field("tags").arrayGet(-1)Default Implementation
Declaration
Swift
func arrayGet(_ offset: Int) -> FunctionExpressionParameters
offsetThe literal
Intoffset of the element to return.Return Value
A new
FunctionExpressionrepresenting the “arrayGet” operation. -
Default implementationarrayGet(_:)
Creates an expression that accesses an element in an array (from
self) at the offset specified by an expression. A negative offset starts from the end. If the offset is out of bounds, an error may be returned during evaluation. Assumesselfevaluates to an array andoffsetExprevaluates to an integer.// Return the value in the tags field array at index specified by field "favoriteTagIndex". Field("tags").arrayGet(Field("favoriteTagIndex"))Default Implementation
Declaration
Swift
func arrayGet(_ offsetExpression: Expression) -> FunctionExpressionParameters
offsetExpressionAn
Expression(evaluating to an Int) representing the offset of the element to return.Return Value
A new
FunctionExpressionrepresenting the “arrayGet” operation. -
Default implementationarrayMaximum()
Creates an expression that returns the maximum element of an array.
Assumes
selfevaluates to an array.// Get the maximum value in the "scores" array. Field("scores").arrayMaximum()Default Implementation
Declaration
Swift
func arrayMaximum() -> FunctionExpressionReturn Value
A new
FunctionExpressionrepresenting the maximum element of the array. -
Default implementationarrayMinimum()
Creates an expression that returns the minimum element of an array.
Assumes
selfevaluates to an array.// Get the minimum value in the "scores" array. Field("scores").arrayMinimum()Default Implementation
Declaration
Swift
func arrayMinimum() -> FunctionExpressionReturn Value
A new
FunctionExpressionrepresenting the minimum element of the array. -
Default implementationgreaterThan(_:)
Creates a
BooleanExpressionthat returnstrueif this expression is greater than the given expression.Default Implementation
Declaration
Swift
func greaterThan(_ other: Expression) -> BooleanExpressionParameters
otherThe expression to compare against.
Return Value
A
BooleanExpressionthat can be used in a where stage, together with other boolean expressions. -
Default implementationgreaterThan(_:)
Creates a
BooleanExpressionthat returnstrueif this expression is greater than the given value.Default Implementation
Declaration
Swift
func greaterThan(_ other: Sendable) -> BooleanExpressionParameters
otherThe value to compare against.
Return Value
A
BooleanExpressionthat can be used in a where stage, together with other boolean expressions. -
Default implementationgreaterThanOrEqual(_:)
Creates a
BooleanExpressionthat returnstrueif this expression is greater than or equal to the given expression.Default Implementation
Declaration
Swift
func greaterThanOrEqual(_ other: Expression) -> BooleanExpressionParameters
otherThe expression to compare against.
Return Value
A
BooleanExpressionthat can be used in a where stage, together with other boolean expressions. -
Default implementationgreaterThanOrEqual(_:)
Creates a
BooleanExpressionthat returnstrueif this expression is greater than or equal to the given value.Default Implementation
Declaration
Swift
func greaterThanOrEqual(_ other: Sendable) -> BooleanExpressionParameters
otherThe value to compare against.
Return Value
A
BooleanExpressionthat can be used in a where stage, together with other boolean expressions. -
Default implementationlessThan(_:)
Creates a
BooleanExpressionthat returnstrueif this expression is less than the given expression.Default Implementation
Declaration
Swift
func lessThan(_ other: Expression) -> BooleanExpressionParameters
otherThe expression to compare against.
Return Value
A
BooleanExpressionthat can be used in a where stage, together with other boolean expressions. -
Default implementationlessThan(_:)
Creates a
BooleanExpressionthat returnstrueif this expression is less than the given value.Default Implementation
Declaration
Swift
func lessThan(_ other: Sendable) -> BooleanExpressionParameters
otherThe value to compare against.
Return Value
A
BooleanExpressionthat can be used in a where stage, together with other boolean expressions. -
Default implementationlessThanOrEqual(_:)
Creates a
BooleanExpressionthat returnstrueif this expression is less than or equal to the given expression.Default Implementation
Declaration
Swift
func lessThanOrEqual(_ other: Expression) -> BooleanExpressionParameters
otherThe expression to compare against.
Return Value
A
BooleanExpressionthat can be used in a where stage, together with other boolean expressions. -
Default implementationlessThanOrEqual(_:)
Creates a
BooleanExpressionthat returnstrueif this expression is less than or equal to the given value.Default Implementation
Declaration
Swift
func lessThanOrEqual(_ other: Sendable) -> BooleanExpressionParameters
otherThe value to compare against.
Return Value
A
BooleanExpressionthat can be used in a where stage, together with other boolean expressions. -
Default implementationequal(_:)
Creates a
BooleanExpressionthat returnstrueif this expression is equal to the given expression.Default Implementation
Declaration
Swift
func equal(_ other: Expression) -> BooleanExpressionParameters
otherThe expression to compare against.
Return Value
A
BooleanExpressionthat can be used in a where stage, together with other boolean expressions. -
Default implementationequal(_:)
Creates a
BooleanExpressionthat returnstrueif this expression is equal to the given value.Default Implementation
Declaration
Swift
func equal(_ other: Sendable) -> BooleanExpressionParameters
otherThe value to compare against.
Return Value
A
BooleanExpressionthat can be used in a where stage, together with other boolean expressions. -
Default implementationnotEqual(_:)
Creates a
BooleanExpressionthat returnstrueif this expression is not equal to the given expression.Default Implementation
Declaration
Swift
func notEqual(_ other: Expression) -> BooleanExpressionParameters
otherThe expression to compare against.
Return Value
A
BooleanExpressionthat can be used in a where stage, together with other boolean expressions. -
Default implementationnotEqual(_:)
Creates a
BooleanExpressionthat returnstrueif this expression is not equal to the given value.Default Implementation
Declaration
Swift
func notEqual(_ other: Sendable) -> BooleanExpressionParameters
otherThe value to compare against.
Return Value
A
BooleanExpressionthat can be used in a where stage, together with other boolean expressions. -
Default implementationequalAny(_:)
Creates an expression that checks if this expression is equal to any of the provided expression values.
// Check if "categoryID" field is equal to "featuredCategory" or "popularCategory" fields Field("categoryID").equalAny([Field("featuredCategory"), Field("popularCategory")])Default Implementation
Declaration
Swift
func equalAny(_ others: [Expression]) -> BooleanExpressionParameters
othersAn array of at least one
Expressionvalue to check against.Return Value
A
BooleanExpressionthat can be used in a where stage, together with other boolean expressions. -
Default implementationequalAny(_:)
Creates an expression that checks if this expression is equal to any of the provided literal values.
// Check if "category" is "Electronics", "Books", or "Home Goods" Field("category").equalAny(["Electronics", "Books", "Home Goods"])Default Implementation
Declaration
Swift
func equalAny(_ others: [Sendable]) -> BooleanExpressionParameters
othersAn array of at least one
Sendableliteral value to check against.Return Value
A
BooleanExpressionthat can be used in a where stage, together with other boolean expressions. -
Default implementationequalAny(_:)
Creates an expression that checks if this expression is equal to any of the provided expression values.
// Check if "categoryID" field is equal to any of "categoryIDs" fields Field("categoryID").equalAny(Field("categoryIDs"))Default Implementation
Declaration
Swift
func equalAny(_ arrayExpression: Expression) -> BooleanExpressionParameters
arrayExpressionAn
Expressionelements evaluated to be array.Return Value
A
BooleanExpressionthat can be used in a where stage, together with other boolean expressions. -
Default implementationnotEqualAny(_:)
Creates an expression that checks if this expression is not equal to any of the provided expression values.
// Check if "statusValue" is not equal to "archivedStatus" or "deletedStatus" fields Field("statusValue").notEqualAny([Field("archivedStatus"), Field("deletedStatus")])Default Implementation
Declaration
Swift
func notEqualAny(_ others: [Expression]) -> BooleanExpressionParameters
othersAn array of at least one
Expressionvalue to check against.Return Value
A
BooleanExpressionthat can be used in a where stage, together with other boolean expressions. -
Default implementationnotEqualAny(_:)
Creates an expression that checks if this expression is not equal to any of the provided literal values.
// Check if "status" is neither "pending" nor "archived" Field("status").notEqualAny(["pending", "archived"])Default Implementation
Declaration
Swift
func notEqualAny(_ others: [Sendable]) -> BooleanExpressionParameters
othersAn array of at least one
Sendableliteral value to check against.Return Value
A
BooleanExpressionthat can be used in a where stage, together with other boolean expressions. -
Default implementationnotEqualAny(_:)
Creates an expression that checks if this expression is equal to any of the provided expression values.
// Check if "categoryID" field is not equal to any of "categoryIDs" fields Field("categoryID").equalAny(Field("categoryIDs"))Default Implementation
Declaration
Swift
func notEqualAny(_ arrayExpression: Expression) -> BooleanExpressionParameters
arrayExpressionAn
Expressionelements evaluated to be array.Return Value
A
BooleanExpressionthat can be used in a where stage, together with other boolean expressions. -
Default implementationexists()
Creates an expression that checks if a field exists in the document.
// Check if the document has a field named "phoneNumber" Field("phoneNumber").exists()Default Implementation
Declaration
Swift
func exists() -> BooleanExpressionReturn Value
A new
BooleanExpressionrepresenting the “exists” check. -
Default implementationisError()
Creates an expression that checks if this expression produces an error during evaluation.
// Check if accessing a non-existent array index causes an error Field("myArray").arrayGet(100).isError()Default Implementation
Declaration
Swift
func isError() -> BooleanExpressionReturn Value
A new
BooleanExpressionrepresenting the “isError” check. -
Default implementationisAbsent()
Creates an expression that returns
trueif the result of this expression is absent (e.g., a field does not exist in a map). Otherwise, returnsfalse.// Check if the field `value` is absent. Field("value").isAbsent()Default Implementation
Declaration
Swift
func isAbsent() -> BooleanExpressionReturn Value
A new
BooleanExpressionrepresenting the “isAbsent” check.
-
Default implementationjoin(delimiter:)
Creates an expression that joins the elements of an array of strings with a given separator.
Assumes
selfevaluates to an array of strings.// Join the "tags" array with a ", " separator. Field("tags").join(separator: ", ")Default Implementation
Declaration
Swift
func join(delimiter: String) -> FunctionExpressionParameters
delimiterThe string to use as a delimiter.
Return Value
A new
FunctionExpressionrepresenting the joined string. -
Default implementationsplit(delimiter:)
Creates an expression that splits a string into an array of substrings based on a delimiter.
Default Implementation
Declaration
Swift
func split(delimiter: String) -> FunctionExpressionParameters
delimiterThe string to split on.
Return Value
A new
FunctionExpressionrepresenting the array of substrings. -
Default implementationsplit(delimiter:)
Creates an expression that splits a string into an array of substrings based on a delimiter.
Default Implementation
Declaration
Swift
func split(delimiter: Expression) -> FunctionExpressionParameters
delimiterAn expression that evaluates to a string or bytes to split on.
Return Value
A new
FunctionExpressionrepresenting the array of substrings. -
Default implementationlength()
Creates an expression that returns the length of a string.
// Get the length of the "name" field. Field("name").length()Default Implementation
Declaration
Swift
func length() -> FunctionExpressionReturn Value
A new
FunctionExpressionrepresenting the length of the string. -
Default implementationcharLength()
Creates an expression that calculates the character length of a string in UTF-8. Assumes
selfevaluates to a string.// Get the character length of the "name" field in its UTF-8 form. Field("name").charLength()Default Implementation
Declaration
Swift
func charLength() -> FunctionExpressionReturn Value
A new
FunctionExpressionrepresenting the length of the string. -
Default implementationlike(_:)
Creates an expression that performs a case-sensitive string comparison using wildcards against a literal pattern. Assumes
selfevaluates to a string.// Check if the "title" field contains the word "guide" (case-sensitive) Field("title").like("%guide%")Default Implementation
Declaration
Swift
func like(_ pattern: String) -> BooleanExpressionParameters
patternThe literal string pattern to search for. Use “%” as a wildcard.
Return Value
A new
BooleanExpressionrepresenting the “like” comparison. -
Default implementationlike(_:)
Creates an expression that performs a case-sensitive string comparison using wildcards against an expression pattern. Assumes
selfevaluates to a string, andpatternevaluates to a string.// Check if "filename" matches a pattern stored in "patternField" Field("filename").like(Field("patternField"))Default Implementation
Declaration
Swift
func like(_ pattern: Expression) -> BooleanExpressionParameters
patternAn
Expression(evaluating to a string) representing the pattern to search for.Return Value
A new
BooleanExpressionrepresenting the “like” comparison. -
Default implementationregexContains(_:)
Creates an expression that checks if a string (from
self) contains a specified regular expression literal as a substring. Assumesselfevaluates to a string.// Check if "description" contains "example" (case-insensitive) Field("description").regexContains("(?i)example")Default Implementation
Declaration
Swift
func regexContains(_ pattern: String) -> BooleanExpressionParameters
patternThe literal string regular expression to use for the search.
Return Value
A new
BooleanExpressionrepresenting the “regex_contains” comparison. -
Default implementationregexContains(_:)
Creates an expression that checks if a string (from
self) contains a specified regular expression (from an expression) as a substring. Assumesselfevaluates to a string, andpatternevaluates to a string.// Check if "logEntry" contains a pattern from "errorPattern" field Field("logEntry").regexContains(Field("errorPattern"))Default Implementation
Declaration
Swift
func regexContains(_ pattern: Expression) -> BooleanExpressionParameters
patternAn
Expression(evaluating to a string) representing the regular expression to use for the search.Return Value
A new
BooleanExpressionrepresenting the “regex_contains” comparison. -
Default implementationregexFind(_:)
Creates an expression that returns the first substring of a string expression that matches a specified regular expression. Assumes
selfevaluates to a string.// Extract the domain name from an email field Field("email").regexFind("@[A-Za-z0-9.-]+")Default Implementation
Declaration
Swift
func regexFind(_ pattern: String) -> FunctionExpressionParameters
patternThe literal string regular expression to search for.
Return Value
A new
FunctionExpressionrepresenting the regular expression find function. -
Default implementationregexFind(_:)
Creates an expression that returns the first substring of a string expression that matches a specified regular expression. Assumes
selfevaluates to a string, andpatternevaluates to a string.// Extract a substring based on a dynamic pattern stored in another field Field("email").regexFind(Field("pattern"))Default Implementation
Declaration
Swift
func regexFind(_ pattern: Expression) -> FunctionExpressionParameters
patternAn
Expression(evaluating to a string) representing the regular expression to search for.Return Value
A new
FunctionExpressionrepresenting the regular expression find function. -
Default implementationregexFindAll(_:)
Creates an expression that evaluates to a list of all substrings in a string expression that match a specified regular expression. Assumes
selfevaluates to a string.// Extract all hashtags from a post content field Field("content").regexFindAll("#[A-Za-z0-9_]+")Default Implementation
Declaration
Swift
func regexFindAll(_ pattern: String) -> FunctionExpressionParameters
patternThe literal string regular expression to search for.
Return Value
A new
FunctionExpressionthat evaluates to an array of matched substrings. -
Default implementationregexFindAll(_:)
Creates an expression that evaluates to a list of all substrings in a string expression that match a specified regular expression. Assumes
selfevaluates to a string, andpatternevaluates to a string.// Extract all matches based on a dynamic pattern stored in another field Field("content").regexFindAll(Field("pattern"))Default Implementation
Declaration
Swift
func regexFindAll(_ pattern: Expression) -> FunctionExpressionParameters
patternAn
Expression(evaluating to a string) representing the regular expression to search for.Return Value
A new
FunctionExpressionthat evaluates to an array of matched substrings. -
Default implementationregexMatch(_:)
Creates an expression that checks if a string (from
self) matches a specified regular expression literal entirely. Assumesselfevaluates to a string.// 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,}")Default Implementation
Declaration
Swift
func regexMatch(_ pattern: String) -> BooleanExpressionParameters
patternThe literal string regular expression to use for the match.
Return Value
A new
BooleanExpressionrepresenting the regular expression match. -
Default implementationregexMatch(_:)
Creates an expression that checks if a string (from
self) matches a specified regular expression (from an expression) entirely. Assumesselfevaluates to a string, andpatternevaluates to a string.// Check if "input" matches the regex stored in "validationRegex" Field("input").regexMatch(Field("validationRegex"))Default Implementation
Declaration
Swift
func regexMatch(_ pattern: Expression) -> BooleanExpressionParameters
patternAn
Expression(evaluating to a string) representing the regular expression to use for the match.Return Value
A new
BooleanExpressionrepresenting the regular expression match. -
Default implementationstringContains(_:)
Creates an expression that checks if a string (from
self) contains a specified literal substring (case-sensitive). Assumesselfevaluates to a string.// Check if the "description" field contains "example". Field("description").stringContains("example")Default Implementation
Declaration
Swift
func stringContains(_ substring: String) -> BooleanExpressionParameters
substringThe literal string substring to search for.
Return Value
A new
BooleanExpressionrepresenting the “stringContains” comparison. -
Default implementationstringContains(_:)
Creates an expression that checks if a string (from
self) contains a specified substring from an expression (case-sensitive). Assumesselfevaluates to a string, andexpressionevaluates to a string.// Check if the "message" field contains the value of the "keyword" field. Field("message").stringContains(Field("keyword"))Default Implementation
Declaration
Swift
func stringContains(_ expression: Expression) -> BooleanExpressionParameters
expressionAn
Expression(evaluating to a string) representing the substring to search for.Return Value
A new
BooleanExpressionrepresenting the “str_contains” comparison. -
Default implementationstartsWith(_:)
Creates an expression that checks if a string (from
self) starts with a given literal prefix (case-sensitive). Assumesselfevaluates to a string.// Check if the "name" field starts with "Mr." Field("name").startsWith("Mr.")Default Implementation
Declaration
Swift
func startsWith(_ prefix: String) -> BooleanExpressionParameters
prefixThe literal string prefix to check for.
Return Value
A new
BooleanExprrepresenting the “starts_with” comparison. -
Default implementationstartsWith(_:)
Creates an expression that checks if a string (from
self) starts with a given prefix from an expression (case-sensitive). Assumesselfevaluates to a string, andprefixevaluates to a string.// Check if "fullName" starts with the value of "firstName" Field("fullName").startsWith(Field("firstName"))Default Implementation
Declaration
Swift
func startsWith(_ prefix: Expression) -> BooleanExpressionParameters
prefixAn
Expression(evaluating to a string) representing the prefix to check for.Return Value
A new
BooleanExprrepresenting the “starts_with” comparison. -
Default implementationendsWith(_:)
Creates an expression that checks if a string (from
self) ends with a given literal suffix (case-sensitive). Assumesselfevaluates to a string.// Check if the "filename" field ends with ".txt" Field("filename").endsWith(".txt")Default Implementation
Declaration
Swift
func endsWith(_ suffix: String) -> BooleanExpressionParameters
suffixThe literal string suffix to check for.
Return Value
A new
BooleanExprrepresenting the “ends_with” comparison. -
Default implementationendsWith(_:)
Creates an expression that checks if a string (from
self) ends with a given suffix from an expression (case-sensitive). Assumesselfevaluates to a string, andsuffixevaluates to a string.// Check if "url" ends with the value of "extension" field Field("url").endsWith(Field("extension"))Default Implementation
Declaration
Swift
func endsWith(_ suffix: Expression) -> BooleanExpressionParameters
suffixAn
Expression(evaluating to a string) representing the suffix to check for.Return Value
A new
BooleanExpressionrepresenting the “ends_with” comparison. -
Default implementationtoLower()
Creates an expression that converts a string (from
self) to lowercase. Assumesselfevaluates to a string.// Convert the "name" field to lowercase Field("name").toLower()Default Implementation
Declaration
Swift
func toLower() -> FunctionExpressionReturn Value
A new
FunctionExpressionrepresenting the lowercase string. -
Default implementationtoUpper()
Creates an expression that converts a string (from
self) to uppercase. Assumesselfevaluates to a string.// Convert the "title" field to uppercase Field("title").toUpper()Default Implementation
Declaration
Swift
func toUpper() -> FunctionExpressionReturn Value
A new
FunctionExpressionrepresenting the uppercase string. -
Default implementationtrim()
Creates an expression that removes leading and trailing whitespace from a string.
Assumes
selfevaluates to a string.// Trim leading/trailing whitespace from the "comment" field. Field("comment").trim()Default Implementation
Declaration
Swift
func trim() -> FunctionExpressionReturn Value
A new
FunctionExpressionrepresenting the trimmed string. -
Default implementationtrim(_:)
Creates an expression that removes leading and trailing occurrences of specified characters from a string (from
self). Assumesselfevaluates to a string, andvalueevaluates to a string.// Trim leading/trailing "xy" from field Field("code").trim(characters: "xy")Default Implementation
Declaration
Swift
func trim(_ value: String) -> FunctionExpressionParameters
valueA
Stringcontaining the characters to trim.Return Value
A new
FunctionExpressionrepresenting the trimmed string. -
Default implementationtrim(_:)
Creates an expression that removes leading and trailing occurrences of specified string (from an expression) from a string (from
self). Assumesselfevaluates to a string, andvalueevaluates to a string.// Trim characters specified by the "trimChars" field from "data" Field("data").trim(characters: Field("trimChars"))Default Implementation
Declaration
Swift
func trim(_ value: Expression) -> FunctionExpressionParameters
valueAn
Expression(evaluating to a string) containing the characters to trim.Return Value
A new
FunctionExpressionrepresenting the trimmed string. -
Default implementationstringConcat(_:)
Creates an expression that concatenates this string expression with other string expressions. Assumes
selfand all parameters evaluate to strings.// Combine "firstName", " ", and "lastName" Field("firstName").stringConcat([" ", Field("lastName")])Default Implementation
Declaration
Swift
func stringConcat(_ strings: [Sendable]) -> FunctionExpressionParameters
stringsAn array of
ExpressionorStringto concatenate.Return Value
A new
FunctionExpressionrepresenting the concatenated string. -
Default implementationstringConcat(_:)
Creates an expression that concatenates this string expression with other string expressions. Assumes
selfand all parameters evaluate to strings.// Combine "firstName", "middleName", and "lastName" fields Field("firstName").stringConcat(Field("middleName"), Field("lastName"))Default Implementation
Declaration
Swift
func stringConcat(_ strings: [Expression]) -> FunctionExpressionParameters
secondStringAn
Expression(evaluating to a string) to concatenate.otherStringsOptional additional
Expression(evaluating to strings) to concatenate.Return Value
A new
FunctionExpressionrepresenting the concatenated string. -
Default implementationreverse()
Creates an expression that reverses this expression. Assumes
selfevaluates to a string.// Reverse the value of the "myString" field. Field("myString").reverse()Default Implementation
Declaration
Swift
func reverse() -> FunctionExpressionReturn Value
A new
FunctionExpressionrepresenting the reversed string. -
Default implementationstringReverse()
Creates an expression that reverses this string expression. Assumes
selfevaluates to a string.// Reverse the value of the "myString" field. Field("myString").stringReverse()Default Implementation
Declaration
Swift
func stringReverse() -> FunctionExpressionReturn Value
A new
FunctionExpressionrepresenting the reversed string. -
Default implementationbyteLength()
Creates an expression that calculates the length of this string or bytes expression in bytes. Assumes
selfevaluates to a string or bytes.// Calculate the length of the "myString" field in bytes. Field("myString").byteLength() // Calculate the size of the "avatar" (Data/Bytes) field. Field("avatar").byteLength()Default Implementation
Declaration
Swift
func byteLength() -> FunctionExpressionReturn Value
A new
FunctionExpressionrepresenting the length in bytes. -
Default implementationsubstring(position:length:)
Creates an expression that returns a substring of this expression (String or Bytes) using literal integers for position and optional length. Indexing is 0-based. Assumes
selfevaluates to a string or bytes.// Get substring from index 5 with length 10 Field("myString").substring(5, 10) // Get substring from "myString" starting at index 3 to the end Field("myString").substring(3) // Default nilDefault Implementation
Declaration
Swift
func substring(position: Int, length: Int?) -> FunctionExpressionParameters
positionLiteral
Intindex of the first character/byte.lengthOptional literal
Intlength of the substring. Ifnil, goes to the end.Return Value
A new
FunctionExpressionrepresenting the substring. -
Default implementationsubstring(position:length:)
Creates an expression that returns a substring of this expression (String or Bytes) using expressions for position and optional length. Indexing is 0-based. Assumes
selfevaluates to a string or bytes, and parameters evaluate to integers.// Get substring from index calculated by Field("start") with length from Field("len") Field("myString").substring(Field("start"), Field("len")) // Get substring from index calculated by Field("start") to the end Field("myString").substring(Field("start")) // Default nil for optional Expression lengthDefault Implementation
Declaration
Swift
func substring(position: Expression, length: Expression?) -> FunctionExpressionParameters
positionAn
Expression(evaluating to an Int) for the index of the first character.lengthOptional
Expression(evaluating to an Int) for the length of the substring. Ifnil, goes to the end.Return Value
A new
FunctionExpressionrepresenting the substring.
-
Default implementationmapGet(_:)
Accesses a value from a map (object) field using the provided literal string key. Assumes
selfevaluates to a Map.// Get the "city" value from the "address" map field Field("address").mapGet("city")Default Implementation
Declaration
Swift
func mapGet(_ subfield: String) -> FunctionExpressionParameters
subfieldThe literal string key to access in the map.
Return Value
A new
FunctionExpressionrepresenting the value associated with the given key. -
Default implementationmapRemove(_:)
Creates an expression that removes a key (specified by a literal string) from the map produced by evaluating this expression. Assumes
selfevaluates to a Map.// Removes the key "baz" from the map held in field "myMap" Field("myMap").mapRemove("baz")Default Implementation
Declaration
Swift
func mapRemove(_ key: String) -> FunctionExpressionParameters
keyThe literal string key to remove from the map.
Return Value
A new
FunctionExpressionrepresenting the “map_remove” operation. -
Default implementationmapRemove(_:)
Creates an expression that removes a key (specified by an expression) from the map produced by evaluating this expression. Assumes
selfevaluates to a Map, andkeyExpressionevaluates to a string.// Removes the key specified by field "keyToRemove" from the map in "settings" Field("settings").mapRemove(Field("keyToRemove"))Default Implementation
Declaration
Swift
func mapRemove(_ keyExpression: Expression) -> FunctionExpressionParameters
keyExpressionAn
Expression(evaluating to a string) representing the key to remove from the map.Return Value
A new
FunctionExpressionrepresenting the “map_remove” operation. -
Default implementationmapMerge(_:)
Creates an expression that merges this map with multiple other map literals. Assumes
selfevaluates to a Map. Later maps overwrite keys from earlier maps.// Merge "settings" field with { "enabled": true } and another map literal { "priority": 1 } Field("settings").mapMerge(["enabled": true], ["priority": 1])Default Implementation
Declaration
Swift
func mapMerge(_ maps: [[String: Sendable]]) -> FunctionExpressionParameters
mapsMaps (dictionary literals with
Sendablevalues) to merge.Return Value
A new
FunctionExpressionrepresenting the “map_merge” operation. -
Default implementationmapMerge(_:)
Creates an expression that merges this map with multiple other map expressions. Assumes
selfand other arguments evaluate to Maps. Later maps overwrite keys from earlier maps.// Merge "baseSettings" field with "userOverrides" field and "adminConfig" field Field("baseSettings").mapMerge(Field("userOverrides"), Field("adminConfig"))Default Implementation
Declaration
Swift
func mapMerge(_ maps: [Expression]) -> FunctionExpressionParameters
mapsAdditional
Expression(evaluating to Maps) to merge.Return Value
A new
FunctionExpressionrepresenting the “map_merge” operation.
-
Default implementationcountDistinct()
Creates an aggregation that counts the number of distinct values of this expression.
// Count the number of distinct categories. Field("category").countDistinct().as("distinctCategories")Default Implementation
Declaration
Swift
func countDistinct() -> AggregateFunctionReturn Value
A new
AggregateFunctionrepresenting the “count_distinct” aggregation. -
Default implementationcount()
Creates an aggregation that counts the number of stage inputs where this expression evaluates to a valid, non-null value.
// Count the total number of products with a "productId" Field("productId").count().alias("totalProducts")Default Implementation
Declaration
Swift
func count() -> AggregateFunctionReturn Value
A new
AggregateFunctionrepresenting the “count” aggregation on this expression. -
Default implementationsum()
Creates an aggregation that calculates the sum of this numeric expression across multiple stage inputs. Assumes
selfevaluates to a numeric type.// Calculate the total revenue from a set of orders Field("orderAmount").sum().alias("totalRevenue")Default Implementation
Declaration
Swift
func sum() -> AggregateFunctionReturn Value
A new
AggregateFunctionrepresenting the “sum” aggregation. -
Default implementationaverage()
Creates an aggregation that calculates the average (mean) of this numeric expression across multiple stage inputs. Assumes
selfevaluates to a numeric type.// Calculate the average age of users Field("age").average().as("averageAge")Default Implementation
Declaration
Swift
func average() -> AggregateFunctionReturn Value
A new
AggregateFunctionrepresenting the “average” aggregation. -
Default implementationminimum()
Creates an aggregation that finds the minimum value of this expression across multiple stage inputs.
// Find the lowest price of all products Field("price").minimum().alias("lowestPrice")Default Implementation
Declaration
Swift
func minimum() -> AggregateFunctionReturn Value
A new
AggregateFunctionrepresenting the “min” aggregation. -
Default implementationmaximum()
Creates an aggregation that finds the maximum value of this expression across multiple stage inputs.
// Find the highest score in a leaderboard Field("score").maximum().alias("highestScore")Default Implementation
Declaration
Swift
func maximum() -> AggregateFunctionReturn Value
A new
AggregateFunctionrepresenting the “max” aggregation. -
Default implementationlogicalMaximum(_:)
Creates an expression that returns the larger value between this expression and other expressions, based on Firestore"s value type ordering.
// Returns the largest of "val1", "val2", and "val3" fields Field("val1").logicalMaximum(Field("val2"), Field("val3"))Default Implementation
Declaration
Swift
func logicalMaximum(_ expressions: [Expression]) -> FunctionExpressionParameters
expressionsAn array of at least one
Expressionto compare with.Return Value
A new
FunctionExpressionrepresenting the logical max operation. -
Default implementationlogicalMaximum(_:)
Creates an expression that returns the larger value between this expression and other literal values, based on Firestore"s value type ordering.
// Returns the largest of "val1" (a field), 100, and 200.0 Field("val1").logicalMaximum(100, 200.0)Default Implementation
Declaration
Swift
func logicalMaximum(_ values: [Sendable]) -> FunctionExpressionParameters
valuesAn array of at least one
Sendablevalue to compare with.Return Value
A new
FunctionExpressionrepresenting the logical max operation. -
Default implementationlogicalMinimum(_:)
Creates an expression that returns the smaller value between this expression and other expressions, based on Firestore"s value type ordering.
// Returns the smallest of "val1", "val2", and "val3" fields Field("val1").logicalMinimum(Field("val2"), Field("val3"))Default Implementation
Declaration
Swift
func logicalMinimum(_ expressions: [Expression]) -> FunctionExpressionParameters
expressionsAn array of at least one
Expressionto compare with.Return Value
A new
FunctionExpressionrepresenting the logical min operation. -
Default implementationlogicalMinimum(_:)
Creates an expression that returns the smaller value between this expression and other literal values, based on Firestore"s value type ordering.
// Returns the smallest of "val1" (a field), 0, and -5.5 Field("val1").logicalMinimum(0, -5.5)Default Implementation
Declaration
Swift
func logicalMinimum(_ values: [Sendable]) -> FunctionExpressionParameters
valuesAn array of at least one
Sendablevalue to compare with.Return Value
A new
FunctionExpressionrepresenting the logical min operation.
-
Default implementationvectorLength()
Creates an expression that calculates the length (number of dimensions) of this Firestore Vector expression. Assumes
selfevaluates to a Vector.// Get the vector length (dimension) of the field "embedding". Field("embedding").vectorLength()Default Implementation
Declaration
Swift
func vectorLength() -> FunctionExpressionReturn Value
A new
FunctionExpressionrepresenting the length of the vector. -
Default implementationcosineDistance(_:)
Calculates the cosine distance between this vector expression and another vector expression. Assumes both
selfandotherevaluate to Vectors.// Cosine distance between "userVector" field and "itemVector" field Field("userVector").cosineDistance(Field("itemVector"))Default Implementation
Declaration
Swift
func cosineDistance(_ expression: Expression) -> FunctionExpressionParameters
expressionThe other vector as an
Exprto compare against.Return Value
A new
FunctionExpressionrepresenting the cosine distance. -
Default implementationcosineDistance(_:)
Calculates the cosine distance between this vector expression and another vector literal (
VectorValue). Assumesselfevaluates to a Vector.// Cosine distance with a VectorValue let targetVector = VectorValue(vector: [0.1, 0.2, 0.3]) Field("docVector").cosineDistance(targetVector)Default Implementation
Declaration
Swift
func cosineDistance(_ vector: VectorValue) -> FunctionExpressionParameters
vectorThe other vector as a
VectorValueto compare against.Return Value
A new
FunctionExpressionrepresenting the cosine distance. -
Default implementationcosineDistance(_:)
Calculates the cosine distance between this vector expression and another vector literal (
[Double]). Assumesselfevaluates to a Vector.// Cosine distance between "location" field and a target location Field("location").cosineDistance([37.7749, -122.4194])Default Implementation
Declaration
Swift
func cosineDistance(_ vector: [Double]) -> FunctionExpressionParameters
vectorThe other vector as
[Double]to compare against.Return Value
A new
FunctionExpressionrepresenting the cosine distance. -
Default implementationdotProduct(_:)
Calculates the dot product between this vector expression and another vector expression. Assumes both
selfandotherevaluate to Vectors.// Dot product between "vectorA" and "vectorB" fields Field("vectorA").dotProduct(Field("vectorB"))Default Implementation
Declaration
Swift
func dotProduct(_ expression: Expression) -> FunctionExpressionParameters
expressionThe other vector as an
Exprto calculate with.Return Value
A new
FunctionExpressionrepresenting the dot product. -
Default implementationdotProduct(_:)
Calculates the dot product between this vector expression and another vector literal (
VectorValue). Assumesselfevaluates to a Vector.// Dot product with a VectorValue let weightVector = VectorValue(vector: [0.5, -0.5]) Field("features").dotProduct(weightVector)Default Implementation
Declaration
Swift
func dotProduct(_ vector: VectorValue) -> FunctionExpressionParameters
vectorThe other vector as a
VectorValueto calculate with.Return Value
A new
FunctionExpressionrepresenting the dot product. -
Default implementationdotProduct(_:)
Calculates the dot product between this vector expression and another vector literal (
[Double]). Assumesselfevaluates to a Vector.// Dot product between a feature vector and a target vector literal Field("features").dotProduct([0.5, 0.8, 0.2])Default Implementation
Declaration
Swift
func dotProduct(_ vector: [Double]) -> FunctionExpressionParameters
vectorThe other vector as
[Double]to calculate with.Return Value
A new
FunctionExpressionrepresenting the dot product. -
Default implementationeuclideanDistance(_:)
Calculates the Euclidean distance between this vector expression and another vector expression. Assumes both
selfandotherevaluate to Vectors.// Euclidean distance between "pointA" and "pointB" fields Field("pointA").euclideanDistance(Field("pointB"))Default Implementation
Declaration
Swift
func euclideanDistance(_ expression: Expression) -> FunctionExpressionParameters
expressionThe other vector as an
Exprto compare against.Return Value
A new
FunctionExpressionrepresenting the Euclidean distance. -
Default implementationeuclideanDistance(_:)
Calculates the Euclidean distance between this vector expression and another vector literal (
VectorValue). Assumesselfevaluates to a Vector.let targetPoint = VectorValue(vector: [1.0, 2.0]) Field("currentLocation").euclideanDistance(targetPoint)Default Implementation
Declaration
Swift
func euclideanDistance(_ vector: VectorValue) -> FunctionExpressionParameters
vectorThe other vector as a
VectorValueto compare against.Return Value
A new
FunctionExpressionrepresenting the Euclidean distance. -
Default implementationeuclideanDistance(_:)
Calculates the Euclidean distance between this vector expression and another vector literal (
[Double]). Assumesselfevaluates to a Vector.// Euclidean distance between "location" field and a target location literal Field("location").euclideanDistance([37.7749, -122.4194])Default Implementation
Declaration
Swift
func euclideanDistance(_ vector: [Double]) -> FunctionExpressionParameters
vectorThe other vector as
[Double]to compare against.Return Value
A new
FunctionExpressionrepresenting the Euclidean distance.
-
Default implementationunixMicrosToTimestamp()
Creates an expression that interprets this expression (evaluating to a number) as microseconds since the Unix epoch and returns a timestamp. Assumes
selfevaluates to a number.// Interpret "microseconds" field as microseconds since epoch. Field("microseconds").unixMicrosToTimestamp()Default Implementation
Declaration
Swift
func unixMicrosToTimestamp() -> FunctionExpressionReturn Value
A new
FunctionExpressionrepresenting the timestamp. -
Default implementationtimestampToUnixMicros()
Creates an expression that converts this timestamp expression to the number of microseconds since the Unix epoch. Assumes
selfevaluates to a Timestamp.// Convert "timestamp" field to microseconds since epoch. Field("timestamp").timestampToUnixMicros()Default Implementation
Declaration
Swift
func timestampToUnixMicros() -> FunctionExpressionReturn Value
A new
FunctionExpressionrepresenting the number of microseconds. -
Default implementationunixMillisToTimestamp()
Creates an expression that interprets this expression (evaluating to a number) as milliseconds since the Unix epoch and returns a timestamp. Assumes
selfevaluates to a number.// Interpret "milliseconds" field as milliseconds since epoch. Field("milliseconds").unixMillisToTimestamp()Default Implementation
Declaration
Swift
func unixMillisToTimestamp() -> FunctionExpressionReturn Value
A new
FunctionExpressionrepresenting the timestamp. -
Default implementationtimestampToUnixMillis()
Creates an expression that converts this timestamp expression to the number of milliseconds since the Unix epoch. Assumes
selfevaluates to a Timestamp.// Convert "timestamp" field to milliseconds since epoch. Field("timestamp").timestampToUnixMillis()Default Implementation
Declaration
Swift
func timestampToUnixMillis() -> FunctionExpressionReturn Value
A new
FunctionExpressionrepresenting the number of milliseconds. -
Default implementationunixSecondsToTimestamp()
Creates an expression that interprets this expression (evaluating to a number) as seconds since the Unix epoch and returns a timestamp. Assumes
selfevaluates to a number.// Interpret "seconds" field as seconds since epoch. Field("seconds").unixSecondsToTimestamp()Default Implementation
Declaration
Swift
func unixSecondsToTimestamp() -> FunctionExpressionReturn Value
A new
FunctionExpressionrepresenting the timestamp. -
Default implementationtimestampToUnixSeconds()
Creates an expression that converts this timestamp expression to the number of seconds since the Unix epoch. Assumes
selfevaluates to a Timestamp.// Convert "timestamp" field to seconds since epoch. Field("timestamp").timestampToUnixSeconds()Default Implementation
Declaration
Swift
func timestampToUnixSeconds() -> FunctionExpressionReturn Value
A new
FunctionExpressionrepresenting the number of seconds. -
Default implementationtimestampTruncate(granularity:)
Creates an expression that truncates a timestamp to a specified granularity. Assumes
selfevaluates to a Timestamp.// Truncate "timestamp" field to the nearest day. Field("timestamp").timestampTruncate(granularity: .day)Default Implementation
Declaration
Swift
func timestampTruncate(granularity: TimeGranularity) -> FunctionExpressionParameters
granularityA
TimeGranularityrepresenting the truncation unit.Return Value
A new
FunctionExpressionrepresenting the truncated timestamp. -
Default implementationtimestampTruncate(granularity:)
Creates an expression that truncates a timestamp to a specified granularity. Assumes
selfevaluates to a Timestamp.// Truncate "timestamp" field to the nearest day using a literal string. Field("timestamp").timestampTruncate(granularity: "day") // Truncate "timestamp" field to the nearest day using an expression. Field("timestamp").timestampTruncate(granularity: Field("granularity_field"))Default Implementation
Declaration
Swift
func timestampTruncate(granularity: Sendable) -> FunctionExpressionParameters
granularityA
Sendableliteral string or anExpressionthat evaluates to a string, specifying the truncation unit.Return Value
A new
FunctionExpressionrepresenting the truncated timestamp. -
Default implementationtimestampAdd(_:_:)
Creates an expression that adds a specified amount of time to this timestamp expression, where unit and amount are provided as literals. Assumes
selfevaluates to a Timestamp.// Add 1 day to the "timestamp" field. Field("timestamp").timestampAdd(1, .day)Default Implementation
Declaration
Swift
func timestampAdd(_ amount: Int, _ unit: TimeUnit) -> FunctionExpressionParameters
unitThe
TimeUnitenum representing the unit of time.amountThe literal
Intamount of the unit to add.Return Value
A new “FunctionExpression” representing the resulting timestamp.
-
Default implementationtimestampAdd(amount:unit:)
Creates an expression that adds a specified amount of time to this timestamp expression, where unit and amount are provided as an expression for amount and a literal for unit. Assumes
selfevaluates to a Timestamp,amountevaluates to an integer, andunitevaluates to a string.// Add duration from "amountField" to "timestamp" with a literal unit "day". Field("timestamp").timestampAdd(amount: Field("amountField"), unit: "day")Default Implementation
Declaration
Swift
func timestampAdd(amount: Expression, unit: Sendable) -> FunctionExpressionParameters
unitA
Sendableliteral string specifying the unit of time. Valid units are “microsecond”, “millisecond”, “second”, “minute”, “hour”, “day”.amountAn
Expressionevaluating to the amount (Int) of the unit to add.Return Value
A new “FunctionExpression” representing the resulting timestamp.
-
Default implementationtimestampSubtract(_:_:)
Creates an expression that subtracts a specified amount of time from this timestamp expression, where unit and amount are provided as literals. Assumes
selfevaluates to a Timestamp.// Subtract 1 day from the "timestamp" field. Field("timestamp").timestampSubtract(1, .day)Default Implementation
Declaration
Swift
func timestampSubtract(_ amount: Int, _ unit: TimeUnit) -> FunctionExpressionParameters
unitThe
TimeUnitenum representing the unit of time.amountThe literal
Intamount of the unit to subtract.Return Value
A new “FunctionExpression” representing the resulting timestamp.
-
Default implementationtimestampSubtract(amount:unit:)
Creates an expression that subtracts a specified amount of time from this timestamp expression, where unit and amount are provided as an expression for amount and a literal for unit. Assumes
selfevaluates to a Timestamp,amountevaluates to an integer, andunitevaluates to a string.// Subtract duration from "amountField" from "timestamp" with a literal unit "day". Field("timestamp").timestampSubtract(amount: Field("amountField"), unit: "day")Default Implementation
Declaration
Swift
func timestampSubtract(amount: Expression, unit: Sendable) -> FunctionExpressionParameters
unitA
Sendableliteral string specifying the unit of time. Valid units are “microsecond”, “millisecond”, “second”, “minute”, “hour”, “day”.amountAn
Expressionevaluating to the amount (Int) of the unit to subtract.Return Value
A new “FunctionExpression” representing the resulting timestamp.
-
Default implementationdocumentId()
Creates an expression that returns the document ID from a path.
// Get the document ID from a path. Field(FieldPath.documentID()).documentId()Default Implementation
Declaration
Swift
func documentId() -> FunctionExpressionReturn Value
A new
FunctionExpressionrepresenting the documentId operation. -
Default implementationcollectionId()
Gets the collection id (kind) of a given document (either an absolute or namespace relative reference). Throw error if the input is the root itself.
Default Implementation
Declaration
Swift
func collectionId() -> FunctionExpression -
Default implementationifError(_:)
Creates an expression that returns the result of
catchExpressionif this expression produces an error during evaluation, otherwise returns the result of this expression.// Try dividing "a" by "b", return field "fallbackValue" on error (e.g., division by zero) Field("a").divide(Field("b")).ifError(Field("fallbackValue"))Default Implementation
Declaration
Swift
func ifError(_ catchExpression: Expression) -> FunctionExpressionParameters
catchExpressionThe
Expressionto evaluate and return if this expression errors.Return Value
A new “FunctionExpression” representing the “ifError” operation.
-
Default implementationifError(_:)
Creates an expression that returns the literal
catchValueif this expression produces an error during evaluation, otherwise returns the result of this expression.// Get first item in "title" array, or return "Default Title" if error (e.g., empty array) Field("title").arrayGet(0).ifError("Default Title")Default Implementation
Declaration
Swift
func ifError(_ catchValue: Sendable) -> FunctionExpressionParameters
catchValueThe literal
Sendablevalue to return if this expression errors.Return Value
A new “FunctionExpression” representing the “ifError” operation.
-
Default implementationifAbsent(_:)
Creates an expression that returns the literal
defaultValueif this expression is absent (e.g., a field does not exist in a map). Otherwise, returns the result of this expression.// If the "optionalField" is absent, return "default value". Field("optionalField").ifAbsent("default value")Default Implementation
Declaration
Swift
func ifAbsent(_ defaultValue: Sendable) -> FunctionExpressionParameters
defaultValueThe literal
Sendablevalue to return if this expression is absent.Return Value
A new “FunctionExpression” representing the “ifAbsent” operation.
-
Default implementationascending()
Creates an
Orderingobject that sorts documents in ascending order based on this expression.// Sort documents by the "name" field in ascending order firestore.pipeline().collection("users") .sort(Field("name").ascending())Default Implementation
Declaration
Swift
func ascending() -> OrderingReturn Value
A new
Orderinginstance for ascending sorting. -
Default implementationdescending()
Creates an
Orderingobject that sorts documents in descending order based on this expression.// Sort documents by the "createdAt" field in descending order firestore.pipeline().collection("users") .sort(Field("createdAt").descending())Default Implementation
Declaration
Swift
func descending() -> OrderingReturn Value
A new
Orderinginstance for descending sorting. -
Default implementationconcat(_:)
Creates an expression that concatenates multiple sequenceable types together.
// Concatenate the firstName and lastName with a space in between. Field("firstName").concat([" ", Field("lastName")])Default Implementation
Declaration
Swift
func concat(_ values: [Sendable]) -> FunctionExpressionParameters
valuesThe values to concatenate.
Return Value
A new
FunctionExpressionrepresenting the concatenated result. -
Default implementationtype()
Creates an expression that returns the type of the expression.
// Get the type of the "rating" field. Field("rating").type()Default Implementation
Declaration
Swift
func type() -> FunctionExpressionReturn Value
A new
FunctionExpressionrepresenting the type of the expression as a string.