Field
public struct Field: Expression, Selectable, BridgeWrapper, SelectableWrapper,
@unchecked SendableA 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 awhereclause. - 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
Fieldexpression from a field name.Declaration
Swift
public init(_ name: String)Parameters
nameThe name 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) -> ExpressionParameters
locationThe target
GeoPoint.Return Value
An
Expressionrepresenting the distance in meters.