FirebaseFirestore Framework Reference

Expression

public protocol Expression : Sendable

Undocumented

  • asBoolean()

    Default implementation

    Casts the expression to a BooleanExpression.

    Default Implementation

    Declaration

    Swift

    func asBoolean() -> BooleanExpression

    Return Value

    A BooleanExpression representing the same expression.

  • as(_:)

    Default implementation

    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) -> AliasedExpression

    Parameters

    name

    The alias to assign to this expression.

    Return Value

    A new AliasedExpression wrapping this expression with the alias.

  • round()

    Default implementation

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

    Return Value

    A new FunctionExpression representing the rounded number.

  • sqrt()

    Default implementation

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

    Return Value

    A new FunctionExpression representing the square root of the number.

  • pow(_:)

    Default implementation

    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) -> FunctionExpression

    Parameters

    exponent

    The exponent to raise self to.

    Return Value

    A new FunctionExpression representing the power of the number.

  • pow(_:)

    Default implementation

    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) -> FunctionExpression

    Parameters

    exponent

    The exponent to raise self to.

    Return Value

    A new FunctionExpression representing the power of the number.

  • ln()

    Default implementation

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

    Return Value

    A new FunctionExpression representing the natural logarithm of the number.

  • floor()

    Default implementation

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

    Return Value

    A new FunctionExpression representing the floor of the number.

  • exp()

    Default implementation

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

    Return Value

    A new FunctionExpression representing the exp of the number.

  • ceil()

    Default implementation

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

    Return Value

    A new FunctionExpression representing the ceiling of the number.

  • abs()

    Default implementation

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

    Return Value

    A new FunctionExpression representing the absolute value of the number.

  • add(_:)

    Default implementation

    Creates an expression that adds another expression to this expression. To add multiple expressions, chain calls to this method. Assumes self and 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) -> FunctionExpression

    Parameters

    value

    An Expression to add.

    Return Value

    A new FunctionExpression representing the addition operation.

  • add(_:)

    Default implementation

    Creates an expression that adds a literal value to this expression. To add multiple literals, chain calls to this method. Assumes self and 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) -> FunctionExpression

    Parameters

    value

    A Sendable literal value to add.

    Return Value

    A new FunctionExpression representing the addition operation.

  • subtract(_:)

    Default implementation

    Creates an expression that subtracts another expression from this expression. Assumes self and other evaluate to numeric types.

    // Subtract the "discount" field from the "price" field
    Field("price").subtract(Field("discount"))
    

    Default Implementation

    Declaration

    Swift

    func subtract(_ other: Expression) -> FunctionExpression

    Parameters

    other

    The Expression (evaluating to a number) to subtract from this expression.

    Return Value

    A new FunctionExpression representing the subtraction operation.

  • subtract(_:)

    Default implementation

    Creates an expression that subtracts a literal value from this expression. Assumes self evaluates 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) -> FunctionExpression

    Parameters

    other

    The Sendable literal (numeric) value to subtract from this expression.

    Return Value

    A new FunctionExpression representing the subtraction operation.

  • multiply(_:)

    Default implementation

    Creates an expression that multiplies this expression by another expression. To multiply multiple expressions, chain calls to this method. Assumes self and 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) -> FunctionExpression

    Parameters

    value

    An Expression to multiply by.

    Return Value

    A new FunctionExpression representing the multiplication operation.

  • multiply(_:)

    Default implementation

    Creates an expression that multiplies this expression by a literal value. To multiply multiple literals, chain calls to this method. Assumes self evaluates 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) -> FunctionExpression

    Parameters

    value

    A Sendable literal value to multiply by.

    Return Value

    A new FunctionExpression representing the multiplication operation.

  • divide(_:)

    Default implementation

    Creates an expression that divides this expression by another expression. Assumes self and other evaluate to numeric types.

    // Divide the "total" field by the "count" field
    Field("total").divide(Field("count"))
    

    Default Implementation

    Declaration

    Swift

    func divide(_ other: Expression) -> FunctionExpression

    Parameters

    other

    The Expression (evaluating to a number) to divide by.

    Return Value

    A new FunctionExpression representing the division operation.

  • divide(_:)

    Default implementation

    Creates an expression that divides this expression by a literal value. Assumes self evaluates to a numeric type.

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

    Default Implementation

    Declaration

    Swift

    func divide(_ other: Sendable) -> FunctionExpression

    Parameters

    other

    The Sendable literal (numeric) value to divide by.

    Return Value

    A new FunctionExpression representing the division operation.

  • mod(_:)

    Default implementation

    Creates an expression that calculates the modulo (remainder) of dividing this expression by another expression. Assumes self and other evaluate 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) -> FunctionExpression

    Parameters

    other

    The Expression (evaluating to a number) to use as the divisor.

    Return Value

    A new FunctionExpression representing the modulo operation.

  • mod(_:)

    Default implementation

    Creates an expression that calculates the modulo (remainder) of dividing this expression by a literal value. Assumes self evaluates 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) -> FunctionExpression

    Parameters

    other

    The Sendable literal (numeric) value to use as the divisor.

    Return Value

    A new FunctionExpression representing the modulo operation.

  • arrayReverse()

    Default implementation

    Creates an expression that returns the input with elements in reverse order.

    // Reverse the "tags" array.
    Field("tags").arrayReverse()
    

    Default Implementation

    Declaration

    Swift

    func arrayReverse() -> FunctionExpression

    Return Value

    A new FunctionExpression representing the reversed array.

  • arrayConcat(_:)

    Default implementation

    Creates an expression that concatenates an array expression (from self) with one or more other array expressions. Assumes self and 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]) -> FunctionExpression

    Parameters

    arrays

    An array of at least one Expression (evaluating to an array) to concatenate.

    Return Value

    A new FunctionExpression representing the concatenated array.

  • arrayConcat(_:)

    Default implementation

    Creates an expression that concatenates an array expression (from self) with one or more array literals. Assumes self evaluates 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]]) -> FunctionExpression

    Parameters

    arrays

    An array of at least one Sendable values to concatenate.

    Return Value

    A new FunctionExpression representing the concatenated array.

  • arrayContains(_:)

    Default implementation

    Creates an expression that checks if an array (from self) contains a specific element expression. Assumes self evaluates 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) -> BooleanExpression

    Parameters

    element

    The Expression representing the element to search for in the array.

    Return Value

    A new BooleanExpr representing the “array_contains” comparison.

  • arrayContains(_:)

    Default implementation

    Creates an expression that checks if an array (from self) contains a specific literal element. Assumes self evaluates to an array.

    // Check if "colors" array contains "red"
    Field("colors").arrayContains("red")
    

    Default Implementation

    Declaration

    Swift

    func arrayContains(_ element: Sendable) -> BooleanExpression

    Parameters

    element

    The Sendable literal element to search for in the array.

    Return Value

    A new BooleanExpr representing the “array_contains” comparison.

  • arrayContainsAll(_:)

    Default implementation

    Creates an expression that checks if an array (from self) contains all the specified element expressions. Assumes self evaluates 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]) -> BooleanExpression

    Parameters

    values

    A list of Expression elements to check for in the array represented by self.

    Return Value

    A new BooleanExpr representing the “array_contains_all” comparison.

  • arrayContainsAll(_:)

    Default implementation

    Creates an expression that checks if an array (from self) contains all the specified literal elements. Assumes self evaluates to an array.

    // Check if "tags" contains both "urgent" and "review"
    Field("tags").arrayContainsAll(["urgent", "review"])
    

    Default Implementation

    Declaration

    Swift

    func arrayContainsAll(_ values: [Sendable]) -> BooleanExpression

    Parameters

    values

    An array of at least one Sendable element to check for in the array.

    Return Value

    A new BooleanExpr representing the “array_contains_all” comparison.

  • arrayContainsAll(_:)

    Default implementation

    Creates an expression that checks if an array (from self) contains all the specified element expressions. Assumes self evaluates 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) -> BooleanExpression

    Parameters

    values

    An Expression elements evaluated to be array.

    Return Value

    A new BooleanExpr representing the “array_contains_all” comparison.

  • arrayContainsAny(_:)

    Default implementation

    Creates an expression that checks if an array (from self) contains any of the specified element expressions. Assumes self evaluates 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]) -> BooleanExpression

    Parameters

    values

    A list of Expression elements to check for in the array.

    Return Value

    A new BooleanExpr representing the “array_contains_any” comparison.

  • arrayContainsAny(_:)

    Default implementation

    Creates an expression that checks if an array (from self) contains any of the specified literal elements. Assumes self evaluates to an array.

    // Check if "categories" contains either "electronics" or "books"
    Field("categories").arrayContainsAny(["electronics", "books"])
    

    Default Implementation

    Declaration

    Swift

    func arrayContainsAny(_ values: [Sendable]) -> BooleanExpression

    Parameters

    values

    An array of at least one Sendable element to check for in the array.

    Return Value

    A new BooleanExpr representing the “array_contains_any” comparison.

  • arrayContainsAny(_:)

    Default implementation

    Creates an expression that checks if an array (from self) contains any of the specified element expressions. Assumes self evaluates 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) -> BooleanExpression

    Parameters

    arrayExpression

    An Expression elements evaluated to be array.

    Return Value

    A new BooleanExpr representing the “array_contains_any” comparison.

  • arrayLength()

    Default implementation

    Creates an expression that calculates the length of an array. Assumes self evaluates to an array.

    // Get the number of items in the "cart" array
    Field("cart").arrayLength()
    

    Default Implementation

    Declaration

    Swift

    func arrayLength() -> FunctionExpression

    Return Value

    A new FunctionExpression representing the length of the array.

  • arrayGet(_:)

    Default implementation

    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. Assumes self evaluates 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) -> FunctionExpression

    Parameters

    offset

    The literal Int offset of the element to return.

    Return Value

    A new FunctionExpression representing the “arrayGet” operation.

  • arrayGet(_:)

    Default implementation

    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. Assumes self evaluates to an array and offsetExpr evaluates 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) -> FunctionExpression

    Parameters

    offsetExpression

    An Expression (evaluating to an Int) representing the offset of the element to return.

    Return Value

    A new FunctionExpression representing the “arrayGet” operation.

  • arrayMaximum()

    Default implementation

    Creates an expression that returns the maximum element of an array.

    Assumes self evaluates to an array.

    // Get the maximum value in the "scores" array.
    Field("scores").arrayMaximum()
    

    Default Implementation

    Declaration

    Swift

    func arrayMaximum() -> FunctionExpression

    Return Value

    A new FunctionExpression representing the maximum element of the array.

  • arrayMinimum()

    Default implementation

    Creates an expression that returns the minimum element of an array.

    Assumes self evaluates to an array.

    // Get the minimum value in the "scores" array.
    Field("scores").arrayMinimum()
    

    Default Implementation

    Declaration

    Swift

    func arrayMinimum() -> FunctionExpression

    Return Value

    A new FunctionExpression representing the minimum element of the array.

  • greaterThan(_:)

    Default implementation

    Creates a BooleanExpression that returns true if this expression is greater than the given expression.

    Default Implementation

    Declaration

    Swift

    func greaterThan(_ other: Expression) -> BooleanExpression

    Parameters

    other

    The expression to compare against.

    Return Value

    A BooleanExpression that can be used in a where stage, together with other boolean expressions.

  • greaterThan(_:)

    Default implementation

    Creates a BooleanExpression that returns true if this expression is greater than the given value.

    Default Implementation

    Declaration

    Swift

    func greaterThan(_ other: Sendable) -> BooleanExpression

    Parameters

    other

    The value to compare against.

    Return Value

    A BooleanExpression that can be used in a where stage, together with other boolean expressions.

  • greaterThanOrEqual(_:)

    Default implementation

    Creates a BooleanExpression that returns true if this expression is greater than or equal to the given expression.

    Default Implementation

    Declaration

    Swift

    func greaterThanOrEqual(_ other: Expression) -> BooleanExpression

    Parameters

    other

    The expression to compare against.

    Return Value

    A BooleanExpression that can be used in a where stage, together with other boolean expressions.

  • greaterThanOrEqual(_:)

    Default implementation

    Creates a BooleanExpression that returns true if this expression is greater than or equal to the given value.

    Default Implementation

    Declaration

    Swift

    func greaterThanOrEqual(_ other: Sendable) -> BooleanExpression

    Parameters

    other

    The value to compare against.

    Return Value

    A BooleanExpression that can be used in a where stage, together with other boolean expressions.

  • lessThan(_:)

    Default implementation

    Creates a BooleanExpression that returns true if this expression is less than the given expression.

    Default Implementation

    Declaration

    Swift

    func lessThan(_ other: Expression) -> BooleanExpression

    Parameters

    other

    The expression to compare against.

    Return Value

    A BooleanExpression that can be used in a where stage, together with other boolean expressions.

  • lessThan(_:)

    Default implementation

    Creates a BooleanExpression that returns true if this expression is less than the given value.

    Default Implementation

    Declaration

    Swift

    func lessThan(_ other: Sendable) -> BooleanExpression

    Parameters

    other

    The value to compare against.

    Return Value

    A BooleanExpression that can be used in a where stage, together with other boolean expressions.

  • lessThanOrEqual(_:)

    Default implementation

    Creates a BooleanExpression that returns true if this expression is less than or equal to the given expression.

    Default Implementation

    Declaration

    Swift

    func lessThanOrEqual(_ other: Expression) -> BooleanExpression

    Parameters

    other

    The expression to compare against.

    Return Value

    A BooleanExpression that can be used in a where stage, together with other boolean expressions.

  • lessThanOrEqual(_:)

    Default implementation

    Creates a BooleanExpression that returns true if this expression is less than or equal to the given value.

    Default Implementation

    Declaration

    Swift

    func lessThanOrEqual(_ other: Sendable) -> BooleanExpression

    Parameters

    other

    The value to compare against.

    Return Value

    A BooleanExpression that can be used in a where stage, together with other boolean expressions.

  • equal(_:)

    Default implementation

    Creates a BooleanExpression that returns true if this expression is equal to the given expression.

    Default Implementation

    Declaration

    Swift

    func equal(_ other: Expression) -> BooleanExpression

    Parameters

    other

    The expression to compare against.

    Return Value

    A BooleanExpression that can be used in a where stage, together with other boolean expressions.

  • equal(_:)

    Default implementation

    Creates a BooleanExpression that returns true if this expression is equal to the given value.

    Default Implementation

    Declaration

    Swift

    func equal(_ other: Sendable) -> BooleanExpression

    Parameters

    other

    The value to compare against.

    Return Value

    A BooleanExpression that can be used in a where stage, together with other boolean expressions.

  • notEqual(_:)

    Default implementation

    Creates a BooleanExpression that returns true if this expression is not equal to the given expression.

    Default Implementation

    Declaration

    Swift

    func notEqual(_ other: Expression) -> BooleanExpression

    Parameters

    other

    The expression to compare against.

    Return Value

    A BooleanExpression that can be used in a where stage, together with other boolean expressions.

  • notEqual(_:)

    Default implementation

    Creates a BooleanExpression that returns true if this expression is not equal to the given value.

    Default Implementation

    Declaration

    Swift

    func notEqual(_ other: Sendable) -> BooleanExpression

    Parameters

    other

    The value to compare against.

    Return Value

    A BooleanExpression that can be used in a where stage, together with other boolean expressions.

  • equalAny(_:)

    Default implementation

    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]) -> BooleanExpression

    Parameters

    others

    An array of at least one Expression value to check against.

    Return Value

    A BooleanExpression that can be used in a where stage, together with other boolean expressions.

  • equalAny(_:)

    Default implementation

    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]) -> BooleanExpression

    Parameters

    others

    An array of at least one Sendable literal value to check against.

    Return Value

    A BooleanExpression that can be used in a where stage, together with other boolean expressions.

  • equalAny(_:)

    Default implementation

    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) -> BooleanExpression

    Parameters

    arrayExpression

    An Expression elements evaluated to be array.

    Return Value

    A BooleanExpression that can be used in a where stage, together with other boolean expressions.

  • notEqualAny(_:)

    Default implementation

    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]) -> BooleanExpression

    Parameters

    others

    An array of at least one Expression value to check against.

    Return Value

    A BooleanExpression that can be used in a where stage, together with other boolean expressions.

  • notEqualAny(_:)

    Default implementation

    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]) -> BooleanExpression

    Parameters

    others

    An array of at least one Sendable literal value to check against.

    Return Value

    A BooleanExpression that can be used in a where stage, together with other boolean expressions.

  • notEqualAny(_:)

    Default implementation

    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) -> BooleanExpression

    Parameters

    arrayExpression

    An Expression elements evaluated to be array.

    Return Value

    A BooleanExpression that can be used in a where stage, together with other boolean expressions.

  • exists()

    Default implementation

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

    Return Value

    A new BooleanExpression representing the “exists” check.

  • isError()

    Default implementation

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

    Return Value

    A new BooleanExpression representing the “isError” check.

  • isAbsent()

    Default implementation

    Creates an expression that returns true if the result of this expression is absent (e.g., a field does not exist in a map). Otherwise, returns false.

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

    Default Implementation

    Declaration

    Swift

    func isAbsent() -> BooleanExpression

    Return Value

    A new BooleanExpression representing the “isAbsent” check.

  • join(delimiter:)

    Default implementation

    Creates an expression that joins the elements of an array of strings with a given separator.

    Assumes self evaluates to an array of strings.

    // Join the "tags" array with a ", " separator.
    Field("tags").join(separator: ", ")
    

    Default Implementation

    Declaration

    Swift

    func join(delimiter: String) -> FunctionExpression

    Parameters

    delimiter

    The string to use as a delimiter.

    Return Value

    A new FunctionExpression representing the joined string.

  • split(delimiter:)

    Default implementation

    Creates an expression that splits a string into an array of substrings based on a delimiter.

    Default Implementation

    Declaration

    Swift

    func split(delimiter: String) -> FunctionExpression

    Parameters

    delimiter

    The string to split on.

    Return Value

    A new FunctionExpression representing the array of substrings.

  • split(delimiter:)

    Default implementation

    Creates an expression that splits a string into an array of substrings based on a delimiter.

    Default Implementation

    Declaration

    Swift

    func split(delimiter: Expression) -> FunctionExpression

    Parameters

    delimiter

    An expression that evaluates to a string or bytes to split on.

    Return Value

    A new FunctionExpression representing the array of substrings.

  • length()

    Default implementation

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

    Return Value

    A new FunctionExpression representing the length of the string.

  • charLength()

    Default implementation

    Creates an expression that calculates the character length of a string in UTF-8. Assumes self evaluates 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() -> FunctionExpression

    Return Value

    A new FunctionExpression representing the length of the string.

  • like(_:)

    Default implementation

    Creates an expression that performs a case-sensitive string comparison using wildcards against a literal pattern. Assumes self evaluates 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) -> BooleanExpression

    Parameters

    pattern

    The literal string pattern to search for. Use “%” as a wildcard.

    Return Value

    A new BooleanExpression representing the “like” comparison.

  • like(_:)

    Default implementation

    Creates an expression that performs a case-sensitive string comparison using wildcards against an expression pattern. Assumes self evaluates to a string, and pattern evaluates 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) -> BooleanExpression

    Parameters

    pattern

    An Expression (evaluating to a string) representing the pattern to search for.

    Return Value

    A new BooleanExpression representing the “like” comparison.

  • regexContains(_:)

    Default implementation

    Creates an expression that checks if a string (from self) contains a specified regular expression literal as a substring. Assumes self evaluates to a string.

    // Check if "description" contains "example" (case-insensitive)
    Field("description").regexContains("(?i)example")
    

    Default Implementation

    Declaration

    Swift

    func regexContains(_ pattern: String) -> BooleanExpression

    Parameters

    pattern

    The literal string regular expression to use for the search.

    Return Value

    A new BooleanExpression representing the “regex_contains” comparison.

  • regexContains(_:)

    Default implementation

    Creates an expression that checks if a string (from self) contains a specified regular expression (from an expression) as a substring. Assumes self evaluates to a string, and pattern evaluates 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) -> BooleanExpression

    Parameters

    pattern

    An Expression (evaluating to a string) representing the regular expression to use for the search.

    Return Value

    A new BooleanExpression representing the “regex_contains” comparison.

  • regexFind(_:)

    Default implementation

    Creates an expression that returns the first substring of a string expression that matches a specified regular expression. Assumes self evaluates 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) -> FunctionExpression

    Parameters

    pattern

    The literal string regular expression to search for.

    Return Value

    A new FunctionExpression representing the regular expression find function.

  • regexFind(_:)

    Default implementation

    Creates an expression that returns the first substring of a string expression that matches a specified regular expression. Assumes self evaluates to a string, and pattern evaluates 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) -> FunctionExpression

    Parameters

    pattern

    An Expression (evaluating to a string) representing the regular expression to search for.

    Return Value

    A new FunctionExpression representing the regular expression find function.

  • regexFindAll(_:)

    Default implementation

    Creates an expression that evaluates to a list of all substrings in a string expression that match a specified regular expression. Assumes self evaluates 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) -> FunctionExpression

    Parameters

    pattern

    The literal string regular expression to search for.

    Return Value

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

  • regexFindAll(_:)

    Default implementation

    Creates an expression that evaluates to a list of all substrings in a string expression that match a specified regular expression. Assumes self evaluates to a string, and pattern evaluates 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) -> FunctionExpression

    Parameters

    pattern

    An Expression (evaluating to a string) representing the regular expression to search for.

    Return Value

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

  • regexMatch(_:)

    Default implementation

    Creates an expression that checks if a string (from self) matches a specified regular expression literal entirely. Assumes self evaluates 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) -> BooleanExpression

    Parameters

    pattern

    The literal string regular expression to use for the match.

    Return Value

    A new BooleanExpression representing the regular expression match.

  • regexMatch(_:)

    Default implementation

    Creates an expression that checks if a string (from self) matches a specified regular expression (from an expression) entirely. Assumes self evaluates to a string, and pattern evaluates 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) -> BooleanExpression

    Parameters

    pattern

    An Expression (evaluating to a string) representing the regular expression to use for the match.

    Return Value

    A new BooleanExpression representing the regular expression match.

  • stringContains(_:)

    Default implementation

    Creates an expression that checks if a string (from self) contains a specified literal substring (case-sensitive). Assumes self evaluates to a string.

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

    Default Implementation

    Declaration

    Swift

    func stringContains(_ substring: String) -> BooleanExpression

    Parameters

    substring

    The literal string substring to search for.

    Return Value

    A new BooleanExpression representing the “stringContains” comparison.

  • stringContains(_:)

    Default implementation

    Creates an expression that checks if a string (from self) contains a specified substring from an expression (case-sensitive). Assumes self evaluates to a string, and expression evaluates 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) -> BooleanExpression

    Parameters

    expression

    An Expression (evaluating to a string) representing the substring to search for.

    Return Value

    A new BooleanExpression representing the “str_contains” comparison.

  • startsWith(_:)

    Default implementation

    Creates an expression that checks if a string (from self) starts with a given literal prefix (case-sensitive). Assumes self evaluates to a string.

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

    Default Implementation

    Declaration

    Swift

    func startsWith(_ prefix: String) -> BooleanExpression

    Parameters

    prefix

    The literal string prefix to check for.

    Return Value

    A new BooleanExpr representing the “starts_with” comparison.

  • startsWith(_:)

    Default implementation

    Creates an expression that checks if a string (from self) starts with a given prefix from an expression (case-sensitive). Assumes self evaluates to a string, and prefix evaluates 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) -> BooleanExpression

    Parameters

    prefix

    An Expression (evaluating to a string) representing the prefix to check for.

    Return Value

    A new BooleanExpr representing the “starts_with” comparison.

  • endsWith(_:)

    Default implementation

    Creates an expression that checks if a string (from self) ends with a given literal suffix (case-sensitive). Assumes self evaluates to a string.

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

    Default Implementation

    Declaration

    Swift

    func endsWith(_ suffix: String) -> BooleanExpression

    Parameters

    suffix

    The literal string suffix to check for.

    Return Value

    A new BooleanExpr representing the “ends_with” comparison.

  • endsWith(_:)

    Default implementation

    Creates an expression that checks if a string (from self) ends with a given suffix from an expression (case-sensitive). Assumes self evaluates to a string, and suffix evaluates 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) -> BooleanExpression

    Parameters

    suffix

    An Expression (evaluating to a string) representing the suffix to check for.

    Return Value

    A new BooleanExpression representing the “ends_with” comparison.

  • toLower()

    Default implementation

    Creates an expression that converts a string (from self) to lowercase. Assumes self evaluates to a string.

    // Convert the "name" field to lowercase
    Field("name").toLower()
    

    Default Implementation

    Declaration

    Swift

    func toLower() -> FunctionExpression

    Return Value

    A new FunctionExpression representing the lowercase string.

  • toUpper()

    Default implementation

    Creates an expression that converts a string (from self) to uppercase. Assumes self evaluates to a string.

    // Convert the "title" field to uppercase
    Field("title").toUpper()
    

    Default Implementation

    Declaration

    Swift

    func toUpper() -> FunctionExpression

    Return Value

    A new FunctionExpression representing the uppercase string.

  • trim()

    Default implementation

    Creates an expression that removes leading and trailing whitespace from a string.

    Assumes self evaluates to a string.

    // Trim leading/trailing whitespace from the "comment" field.
    Field("comment").trim()
    

    Default Implementation

    Declaration

    Swift

    func trim() -> FunctionExpression

    Return Value

    A new FunctionExpression representing the trimmed string.

  • trim(_:)

    Default implementation

    Creates an expression that removes leading and trailing occurrences of specified characters from a string (from self). Assumes self evaluates to a string, and value evaluates to a string.

    // Trim leading/trailing "xy" from field
    Field("code").trim(characters: "xy")
    

    Default Implementation

    Declaration

    Swift

    func trim(_ value: String) -> FunctionExpression

    Parameters

    value

    A String containing the characters to trim.

    Return Value

    A new FunctionExpression representing the trimmed string.

  • trim(_:)

    Default implementation

    Creates an expression that removes leading and trailing occurrences of specified string (from an expression) from a string (from self). Assumes self evaluates to a string, and value evaluates 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) -> FunctionExpression

    Parameters

    value

    An Expression (evaluating to a string) containing the characters to trim.

    Return Value

    A new FunctionExpression representing the trimmed string.

  • stringConcat(_:)

    Default implementation

    Creates an expression that concatenates this string expression with other string expressions. Assumes self and all parameters evaluate to strings.

    // Combine "firstName", " ", and "lastName"
    Field("firstName").stringConcat([" ", Field("lastName")])
    

    Default Implementation

    Declaration

    Swift

    func stringConcat(_ strings: [Sendable]) -> FunctionExpression

    Parameters

    strings

    An array of Expression or String to concatenate.

    Return Value

    A new FunctionExpression representing the concatenated string.

  • stringConcat(_:)

    Default implementation

    Creates an expression that concatenates this string expression with other string expressions. Assumes self and 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]) -> FunctionExpression

    Parameters

    secondString

    An Expression (evaluating to a string) to concatenate.

    otherStrings

    Optional additional Expression (evaluating to strings) to concatenate.

    Return Value

    A new FunctionExpression representing the concatenated string.

  • reverse()

    Default implementation

    Creates an expression that reverses this expression. Assumes self evaluates to a string.

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

    Default Implementation

    Declaration

    Swift

    func reverse() -> FunctionExpression

    Return Value

    A new FunctionExpression representing the reversed string.

  • stringReverse()

    Default implementation

    Creates an expression that reverses this string expression. Assumes self evaluates to a string.

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

    Default Implementation

    Declaration

    Swift

    func stringReverse() -> FunctionExpression

    Return Value

    A new FunctionExpression representing the reversed string.

  • byteLength()

    Default implementation

    Creates an expression that calculates the length of this string or bytes expression in bytes. Assumes self evaluates 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() -> FunctionExpression

    Return Value

    A new FunctionExpression representing the length in bytes.

  • substring(position:length:)

    Default implementation

    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 self evaluates 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 nil
    

    Default Implementation

    Declaration

    Swift

    func substring(position: Int, length: Int?) -> FunctionExpression

    Parameters

    position

    Literal Int index of the first character/byte.

    length

    Optional literal Int length of the substring. If nil, goes to the end.

    Return Value

    A new FunctionExpression representing the substring.

  • substring(position:length:)

    Default implementation

    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 self evaluates 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 length
    

    Default Implementation

    Declaration

    Swift

    func substring(position: Expression, length: Expression?) -> FunctionExpression

    Parameters

    position

    An Expression (evaluating to an Int) for the index of the first character.

    length

    Optional Expression (evaluating to an Int) for the length of the substring. If nil, goes to the end.

    Return Value

    A new FunctionExpression representing the substring.

  • mapGet(_:)

    Default implementation

    Accesses a value from a map (object) field using the provided literal string key. Assumes self evaluates to a Map.

    // Get the "city" value from the "address" map field
    Field("address").mapGet("city")
    

    Default Implementation

    Declaration

    Swift

    func mapGet(_ subfield: String) -> FunctionExpression

    Parameters

    subfield

    The literal string key to access in the map.

    Return Value

    A new FunctionExpression representing the value associated with the given key.

  • mapRemove(_:)

    Default implementation

    Creates an expression that removes a key (specified by a literal string) from the map produced by evaluating this expression. Assumes self evaluates 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) -> FunctionExpression

    Parameters

    key

    The literal string key to remove from the map.

    Return Value

    A new FunctionExpression representing the “map_remove” operation.

  • mapRemove(_:)

    Default implementation

    Creates an expression that removes a key (specified by an expression) from the map produced by evaluating this expression. Assumes self evaluates to a Map, and keyExpression evaluates 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) -> FunctionExpression

    Parameters

    keyExpression

    An Expression (evaluating to a string) representing the key to remove from the map.

    Return Value

    A new FunctionExpression representing the “map_remove” operation.

  • mapMerge(_:)

    Default implementation

    Creates an expression that merges this map with multiple other map literals. Assumes self evaluates 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]])
      -> FunctionExpression

    Parameters

    maps

    Maps (dictionary literals with Sendable values) to merge.

    Return Value

    A new FunctionExpression representing the “map_merge” operation.

  • mapMerge(_:)

    Default implementation

    Creates an expression that merges this map with multiple other map expressions. Assumes self and 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]) -> FunctionExpression

    Parameters

    maps

    Additional Expression (evaluating to Maps) to merge.

    Return Value

    A new FunctionExpression representing the “map_merge” operation.

  • countDistinct()

    Default implementation

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

    Return Value

    A new AggregateFunction representing the “count_distinct” aggregation.

  • count()

    Default implementation

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

    Return Value

    A new AggregateFunction representing the “count” aggregation on this expression.

  • sum()

    Default implementation

    Creates an aggregation that calculates the sum of this numeric expression across multiple stage inputs. Assumes self evaluates to a numeric type.

    // Calculate the total revenue from a set of orders
    Field("orderAmount").sum().alias("totalRevenue")
    

    Default Implementation

    Declaration

    Swift

    func sum() -> AggregateFunction

    Return Value

    A new AggregateFunction representing the “sum” aggregation.

  • average()

    Default implementation

    Creates an aggregation that calculates the average (mean) of this numeric expression across multiple stage inputs. Assumes self evaluates to a numeric type.

    // Calculate the average age of users
    Field("age").average().as("averageAge")
    

    Default Implementation

    Declaration

    Swift

    func average() -> AggregateFunction

    Return Value

    A new AggregateFunction representing the “average” aggregation.

  • minimum()

    Default implementation

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

    Return Value

    A new AggregateFunction representing the “min” aggregation.

  • maximum()

    Default implementation

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

    Return Value

    A new AggregateFunction representing the “max” aggregation.

  • logicalMaximum(_:)

    Default implementation

    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]) -> FunctionExpression

    Parameters

    expressions

    An array of at least one Expression to compare with.

    Return Value

    A new FunctionExpression representing the logical max operation.

  • logicalMaximum(_:)

    Default implementation

    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]) -> FunctionExpression

    Parameters

    values

    An array of at least one Sendable value to compare with.

    Return Value

    A new FunctionExpression representing the logical max operation.

  • logicalMinimum(_:)

    Default implementation

    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]) -> FunctionExpression

    Parameters

    expressions

    An array of at least one Expression to compare with.

    Return Value

    A new FunctionExpression representing the logical min operation.

  • logicalMinimum(_:)

    Default implementation

    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]) -> FunctionExpression

    Parameters

    values

    An array of at least one Sendable value to compare with.

    Return Value

    A new FunctionExpression representing the logical min operation.

  • vectorLength()

    Default implementation

    Creates an expression that calculates the length (number of dimensions) of this Firestore Vector expression. Assumes self evaluates to a Vector.

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

    Default Implementation

    Declaration

    Swift

    func vectorLength() -> FunctionExpression

    Return Value

    A new FunctionExpression representing the length of the vector.

  • cosineDistance(_:)

    Default implementation

    Calculates the cosine distance between this vector expression and another vector expression. Assumes both self and other evaluate to Vectors.

    // Cosine distance between "userVector" field and "itemVector" field
    Field("userVector").cosineDistance(Field("itemVector"))
    

    Default Implementation

    Declaration

    Swift

    func cosineDistance(_ expression: Expression) -> FunctionExpression

    Parameters

    expression

    The other vector as an Expr to compare against.

    Return Value

    A new FunctionExpression representing the cosine distance.

  • cosineDistance(_:)

    Default implementation

    Calculates the cosine distance between this vector expression and another vector literal (VectorValue). Assumes self evaluates 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) -> FunctionExpression

    Parameters

    vector

    The other vector as a VectorValue to compare against.

    Return Value

    A new FunctionExpression representing the cosine distance.

  • cosineDistance(_:)

    Default implementation

    Calculates the cosine distance between this vector expression and another vector literal ([Double]). Assumes self evaluates 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]) -> FunctionExpression

    Parameters

    vector

    The other vector as [Double] to compare against.

    Return Value

    A new FunctionExpression representing the cosine distance.

  • dotProduct(_:)

    Default implementation

    Calculates the dot product between this vector expression and another vector expression. Assumes both self and other evaluate to Vectors.

    // Dot product between "vectorA" and "vectorB" fields
    Field("vectorA").dotProduct(Field("vectorB"))
    

    Default Implementation

    Declaration

    Swift

    func dotProduct(_ expression: Expression) -> FunctionExpression

    Parameters

    expression

    The other vector as an Expr to calculate with.

    Return Value

    A new FunctionExpression representing the dot product.

  • dotProduct(_:)

    Default implementation

    Calculates the dot product between this vector expression and another vector literal (VectorValue). Assumes self evaluates 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) -> FunctionExpression

    Parameters

    vector

    The other vector as a VectorValue to calculate with.

    Return Value

    A new FunctionExpression representing the dot product.

  • dotProduct(_:)

    Default implementation

    Calculates the dot product between this vector expression and another vector literal ([Double]). Assumes self evaluates 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]) -> FunctionExpression

    Parameters

    vector

    The other vector as [Double] to calculate with.

    Return Value

    A new FunctionExpression representing the dot product.

  • euclideanDistance(_:)

    Default implementation

    Calculates the Euclidean distance between this vector expression and another vector expression. Assumes both self and other evaluate to Vectors.

    // Euclidean distance between "pointA" and "pointB" fields
    Field("pointA").euclideanDistance(Field("pointB"))
    

    Default Implementation

    Declaration

    Swift

    func euclideanDistance(_ expression: Expression) -> FunctionExpression

    Parameters

    expression

    The other vector as an Expr to compare against.

    Return Value

    A new FunctionExpression representing the Euclidean distance.

  • euclideanDistance(_:)

    Default implementation

    Calculates the Euclidean distance between this vector expression and another vector literal (VectorValue). Assumes self evaluates to a Vector.

    let targetPoint = VectorValue(vector: [1.0, 2.0])
    Field("currentLocation").euclideanDistance(targetPoint)
    

    Default Implementation

    Declaration

    Swift

    func euclideanDistance(_ vector: VectorValue) -> FunctionExpression

    Parameters

    vector

    The other vector as a VectorValue to compare against.

    Return Value

    A new FunctionExpression representing the Euclidean distance.

  • euclideanDistance(_:)

    Default implementation

    Calculates the Euclidean distance between this vector expression and another vector literal ([Double]). Assumes self evaluates 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]) -> FunctionExpression

    Parameters

    vector

    The other vector as [Double] to compare against.

    Return Value

    A new FunctionExpression representing the Euclidean distance.

  • unixMicrosToTimestamp()

    Default implementation

    Creates an expression that interprets this expression (evaluating to a number) as microseconds since the Unix epoch and returns a timestamp. Assumes self evaluates to a number.

    // Interpret "microseconds" field as microseconds since epoch.
    Field("microseconds").unixMicrosToTimestamp()
    

    Default Implementation

    Declaration

    Swift

    func unixMicrosToTimestamp() -> FunctionExpression

    Return Value

    A new FunctionExpression representing the timestamp.

  • timestampToUnixMicros()

    Default implementation

    Creates an expression that converts this timestamp expression to the number of microseconds since the Unix epoch. Assumes self evaluates to a Timestamp.

    // Convert "timestamp" field to microseconds since epoch.
    Field("timestamp").timestampToUnixMicros()
    

    Default Implementation

    Declaration

    Swift

    func timestampToUnixMicros() -> FunctionExpression

    Return Value

    A new FunctionExpression representing the number of microseconds.

  • unixMillisToTimestamp()

    Default implementation

    Creates an expression that interprets this expression (evaluating to a number) as milliseconds since the Unix epoch and returns a timestamp. Assumes self evaluates to a number.

    // Interpret "milliseconds" field as milliseconds since epoch.
    Field("milliseconds").unixMillisToTimestamp()
    

    Default Implementation

    Declaration

    Swift

    func unixMillisToTimestamp() -> FunctionExpression

    Return Value

    A new FunctionExpression representing the timestamp.

  • timestampToUnixMillis()

    Default implementation

    Creates an expression that converts this timestamp expression to the number of milliseconds since the Unix epoch. Assumes self evaluates to a Timestamp.

    // Convert "timestamp" field to milliseconds since epoch.
    Field("timestamp").timestampToUnixMillis()
    

    Default Implementation

    Declaration

    Swift

    func timestampToUnixMillis() -> FunctionExpression

    Return Value

    A new FunctionExpression representing the number of milliseconds.

  • unixSecondsToTimestamp()

    Default implementation

    Creates an expression that interprets this expression (evaluating to a number) as seconds since the Unix epoch and returns a timestamp. Assumes self evaluates to a number.

    // Interpret "seconds" field as seconds since epoch.
    Field("seconds").unixSecondsToTimestamp()
    

    Default Implementation

    Declaration

    Swift

    func unixSecondsToTimestamp() -> FunctionExpression

    Return Value

    A new FunctionExpression representing the timestamp.

  • timestampToUnixSeconds()

    Default implementation

    Creates an expression that converts this timestamp expression to the number of seconds since the Unix epoch. Assumes self evaluates to a Timestamp.

    // Convert "timestamp" field to seconds since epoch.
    Field("timestamp").timestampToUnixSeconds()
    

    Default Implementation

    Declaration

    Swift

    func timestampToUnixSeconds() -> FunctionExpression

    Return Value

    A new FunctionExpression representing the number of seconds.

  • timestampTruncate(granularity:)

    Default implementation

    Creates an expression that truncates a timestamp to a specified granularity. Assumes self evaluates to a Timestamp.

    // Truncate "timestamp" field to the nearest day.
    Field("timestamp").timestampTruncate(granularity: .day)
    

    Default Implementation

    Declaration

    Swift

    func timestampTruncate(granularity: TimeGranularity) -> FunctionExpression

    Parameters

    granularity

    A TimeGranularity representing the truncation unit.

    Return Value

    A new FunctionExpression representing the truncated timestamp.

  • timestampTruncate(granularity:)

    Default implementation

    Creates an expression that truncates a timestamp to a specified granularity. Assumes self evaluates 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) -> FunctionExpression

    Parameters

    granularity

    A Sendable literal string or an Expression that evaluates to a string, specifying the truncation unit.

    Return Value

    A new FunctionExpression representing the truncated timestamp.

  • timestampAdd(_:_:)

    Default implementation

    Creates an expression that adds a specified amount of time to this timestamp expression, where unit and amount are provided as literals. Assumes self evaluates 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) -> FunctionExpression

    Parameters

    unit

    The TimeUnit enum representing the unit of time.

    amount

    The literal Int amount of the unit to add.

    Return Value

    A new “FunctionExpression” representing the resulting timestamp.

  • timestampAdd(amount:unit:)

    Default implementation

    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 self evaluates to a Timestamp, amount evaluates to an integer, and unit evaluates 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) -> FunctionExpression

    Parameters

    unit

    A Sendable literal string specifying the unit of time. Valid units are “microsecond”, “millisecond”, “second”, “minute”, “hour”, “day”.

    amount

    An Expression evaluating to the amount (Int) of the unit to add.

    Return Value

    A new “FunctionExpression” representing the resulting timestamp.

  • timestampSubtract(_:_:)

    Default implementation

    Creates an expression that subtracts a specified amount of time from this timestamp expression, where unit and amount are provided as literals. Assumes self evaluates 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) -> FunctionExpression

    Parameters

    unit

    The TimeUnit enum representing the unit of time.

    amount

    The literal Int amount of the unit to subtract.

    Return Value

    A new “FunctionExpression” representing the resulting timestamp.

  • timestampSubtract(amount:unit:)

    Default implementation

    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 self evaluates to a Timestamp, amount evaluates to an integer, and unit evaluates 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) -> FunctionExpression

    Parameters

    unit

    A Sendable literal string specifying the unit of time. Valid units are “microsecond”, “millisecond”, “second”, “minute”, “hour”, “day”.

    amount

    An Expression evaluating to the amount (Int) of the unit to subtract.

    Return Value

    A new “FunctionExpression” representing the resulting timestamp.

  • documentId()

    Default implementation

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

    Return Value

    A new FunctionExpression representing the documentId operation.

  • collectionId()

    Default implementation

    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
  • ifError(_:)

    Default implementation

    Creates an expression that returns the result of catchExpression if 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) -> FunctionExpression

    Parameters

    catchExpression

    The Expression to evaluate and return if this expression errors.

    Return Value

    A new “FunctionExpression” representing the “ifError” operation.

  • ifError(_:)

    Default implementation

    Creates an expression that returns the literal catchValue if 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) -> FunctionExpression

    Parameters

    catchValue

    The literal Sendable value to return if this expression errors.

    Return Value

    A new “FunctionExpression” representing the “ifError” operation.

  • ifAbsent(_:)

    Default implementation

    Creates an expression that returns the literal defaultValue if 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) -> FunctionExpression

    Parameters

    defaultValue

    The literal Sendable value to return if this expression is absent.

    Return Value

    A new “FunctionExpression” representing the “ifAbsent” operation.

  • ascending()

    Default implementation

    Creates an Ordering object 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() -> Ordering

    Return Value

    A new Ordering instance for ascending sorting.

  • descending()

    Default implementation

    Creates an Ordering object 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() -> Ordering

    Return Value

    A new Ordering instance for descending sorting.

  • concat(_:)

    Default implementation

    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]) -> FunctionExpression

    Parameters

    values

    The values to concatenate.

    Return Value

    A new FunctionExpression representing the concatenated result.

  • type()

    Default implementation

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

    Return Value

    A new FunctionExpression representing the type of the expression as a string.