Class Pipelines.Field (9.3.1)

Represents a reference to a field in a Firestore document, or outputs of a Pipeline stage.

Field references are used to access document field values in expressions and to specify fields for sorting, filtering, and projecting data in Firestore pipelines.

You can create a Field instance using the static field method:

// Create a Field instance for the 'name' field
const nameField = field("name");

// Create a Field instance for a nested field 'address.city'
const cityField = field("address.city");

Inheritance

Expression > Pipelines.Field

Implements

firestore.Pipelines.Selectable

Package

@google-cloud/firestore

Remarks

The constructor for this class is marked as internal. Third-party code should not call the constructor directly or create subclasses that extend the Field class.

Properties

_alias

get _alias(): string;

_expr

get _expr(): Expression;

expressionType

readonly expressionType: firestore.Pipelines.ExpressionType;

fieldName

get fieldName(): string;

selectable

selectable: true;

Methods

geoDistance(location)

geoDistance(location: GeoPoint | Expression): Expression;

Evaluates to the distance in meters between the location specified by this field and the query location.

Parameter
Name Description
location GeoPoint | Expression

Compute distance to this GeoPoint.

Returns
Type Description
Expression

An Expression representing the geoDistance function.

Remarks

This Expression can only be used within a search stage.

Example
typescript
const geoDistanceToUser = field('location').geoDistance(new GeoPoint(39.7541, -105.0002));

db.pipeline().collection('restaurants').search({
  query: geoDistanceToUser.lessThanOrEqual(2000),
  sort: geoDistanceToUser.ascending()
})