FirebaseFirestore Framework Reference

Field

public struct Field: Expression, Selectable, BridgeWrapper, SelectableWrapper,
  @unchecked Sendable

A Field is an Expression that represents a field in a Firestore document.

It is a central component for building queries and transformations in Firestore pipelines. A Field can be used to:

  • Reference a document field by its name or FieldPath.
  • Create complex BooleanExpressions for filtering in a where clause.
  • Perform mathematical operations on numeric fields.
  • Manipulate string and array fields.

Example of creating a Field and using it in a where clause:

// Reference the "price" field in a document
let priceField = Field("price")

// Create a query to find products where the price is greater than 100
firestore.pipeline()
  .collection("products")
  .where(priceField.greaterThan(100))
  • The name of the field.

    Declaration

    Swift

    public let fieldName: String
  • Creates a new Field expression from a field name.

    Declaration

    Swift

    public init(_ name: String)

    Parameters

    name

    The name of the field.

  • Creates a new Field expression from a FieldPath.

    Declaration

    Swift

    public init(_ path: FieldPath)

    Parameters

    path

    The FieldPath of the field.

  • Calculates the distance between the GeoPoint in this field and a target location.

    Note

    This API is in beta.

    Example usage:

    firestore.pipeline().collection("restaurants")
    .search(
      query: Field("location").geoDistance(GeoPoint(37.937946, -107.813806)).lessThan(1000 /*
    meters */)
    )
    

    Declaration

    Swift

    public func geoDistance(_ location: FirebaseFirestore.GeoPoint) -> Expression

    Parameters

    location

    The target GeoPoint.

    Return Value

    An Expression representing the distance in meters.