Pipeline

A pipeline: a source (from FirebaseFirestore.pipeline) followed by stages that filter, transform and aggregate the documents, run by execute. Immutable: each stage method returns a new pipeline with the stage appended.

On Apple platforms, execute with ExecuteOptions that set options other than ExecuteOptions.withAtomic, and source stages with options other than the forced index (CollectionHints.withForceIndex), fail: the iOS SDK's pipeline bridge has no way to pass them.

Types

Link copied to clipboard

The options of an execution; besides the typed ones, with sets an option by its backend name. The iOS SDK takes only withAtomic: on Apple platforms, executing with any other fails with UnsupportedOperationException.

Link copied to clipboard

The results of an execution, in order, and when the backend computed them.

Functions

Link copied to clipboard
fun addFields(field: Selectable, vararg additionalFields: Selectable): Pipeline

Adds field and additionalFields to the documents.

Link copied to clipboard
fun aggregate(aggregateStage: AggregateStage): Pipeline

Appends the aggregation aggregateStage.

fun aggregate(aggregateStage: AggregateStage, options: AggregateOptions): Pipeline

Appends the aggregation aggregateStage with options.

fun aggregate(accumulator: AliasedAggregate, vararg additionalAccumulators: AliasedAggregate): Pipeline

Replaces the documents with one document holding accumulator and additionalAccumulators.

Link copied to clipboard
fun define(aliasedExpression: AliasedExpression, vararg additionalExpressions: AliasedExpression): Pipeline

Binds aliasedExpression and additionalExpressions to variables, by their aliases, for the following stages.

Link copied to clipboard

Deletes each document of the previous stages from the database.

Link copied to clipboard
fun distinct(group: Selectable, vararg additionalGroups: Any): Pipeline

Keeps one document per distinct value of group and additionalGroups (selectables or field names).

fun distinct(groupField: String, vararg additionalGroups: Any): Pipeline

Keeps one document per distinct value of the field groupField and additionalGroups (selectables or field names).

Link copied to clipboard

Runs the pipeline and completes with its results.

Runs the pipeline with options and completes with its results; on Apple platforms options are not supported (see ExecuteOptions).

Link copied to clipboard
fun findNearest(vectorField: Field, vectorValue: DoubleArray, distanceMeasure: FindNearestStage.DistanceMeasure): Pipeline
fun findNearest(vectorField: String, vectorValue: DoubleArray, distanceMeasure: FindNearestStage.DistanceMeasure): Pipeline

Keeps the documents whose vector field vectorField is nearest to vectorValue by distanceMeasure.

fun findNearest(vectorField: String, vectorValue: Expression, distanceMeasure: FindNearestStage.DistanceMeasure, options: FindNearestOptions): Pipeline

Keeps the documents whose vector field vectorField is nearest to vectorValue by distanceMeasure, with options.

Link copied to clipboard

Inserts each document of the previous stages at the path in its __name__ field; fails if the document exists.

Inserts each document of the previous stages into collection, with its own id or a new one.

fun insert(documentIdExpression: Expression): Pipeline

Inserts each document of the previous stages into its own collection, with the id documentIdExpression evaluates to.

fun insert(collectionPath: String): Pipeline

Inserts each document of the previous stages into the collection at collectionPath, with its own id or a new one.

fun insert(collection: CollectionReference, documentIdExpression: Expression): Pipeline

Inserts each document of the previous stages into collection, with the id documentIdExpression evaluates to.

fun insert(collectionPath: String, documentIdExpression: Expression): Pipeline

Inserts each document of the previous stages into the collection at collectionPath, with the id documentIdExpression evaluates to.

Link copied to clipboard
fun limit(limit: Int): Pipeline

Keeps the first limit documents.

Link copied to clipboard
fun offset(offset: Int): Pipeline

Skips the first offset documents.

Link copied to clipboard
fun rawStage(rawStage: RawStage): Pipeline

Appends rawStage, a stage by its backend name.

Link copied to clipboard
fun removeFields(field: Field, vararg additionalFields: Field): Pipeline

Removes field and additionalFields from the documents.

fun removeFields(field: String, vararg additionalFields: String): Pipeline

Removes the fields field and additionalFields from the documents.

Link copied to clipboard

Replaces each document with the map mapValue.

Replaces each document with the map in its field field.

Link copied to clipboard

Keeps the random sample sample.

fun sample(documents: Int): Pipeline

Keeps a random sample of at most documents documents.

Link copied to clipboard
fun search(searchStage: SearchStage): Pipeline

Appends the search searchStage. Beta in the Android SDK.

Link copied to clipboard
fun select(selection: Selectable, vararg additionalSelections: Any): Pipeline

Replaces the documents with selection and additionalSelections (selectables or field names).

fun select(fieldName: String, vararg additionalSelections: Any): Pipeline

Replaces the documents with the field fieldName and additionalSelections (selectables or field names).

Link copied to clipboard
fun sort(order: Ordering, vararg additionalOrders: Ordering): Pipeline

Sorts the documents by order, then by additionalOrders.

Link copied to clipboard

This pipeline as a subquery evaluating to the array of its results.

Link copied to clipboard

This pipeline as a subquery evaluating to its single result.

Link copied to clipboard
fun union(other: Pipeline): Pipeline

Adds the documents of other.

Link copied to clipboard
fun unnest(arrayWithAlias: Selectable): Pipeline

One document per element of the array arrayWithAlias, the element under its alias.

fun unnest(unnestStage: UnnestStage): Pipeline

Appends unnestStage.

fun unnest(arrayWithAlias: Selectable, options: UnnestOptions): Pipeline

One document per element of the array arrayWithAlias, the element under its alias, with options.

fun unnest(arrayField: String, alias: String): Pipeline

One document per element of the array field arrayField, the element under alias.

Link copied to clipboard
fun update(vararg fields: Selectable): Pipeline

Writes each document of the previous stages back to its path, with fields set under their aliases; the stored document is replaced, so fields earlier stages removed are removed from it too. Creates no documents.

Link copied to clipboard

Writes each document of the previous stages to collection, with its own id or a new one, creating or replacing the document.

fun upsert(collectionPath: String): Pipeline

Writes each document of the previous stages to the collection at collectionPath, with its own id or a new one, creating or replacing the document.

fun upsert(vararg additionalFields: Selectable): Pipeline

Writes each document of the previous stages, with additionalFields added, to the path in its __name__ field, creating or replacing the document (stored fields are not merged).

fun upsert(collection: CollectionReference, documentIdExpression: Expression): Pipeline

Writes each document of the previous stages to collection, with the id documentIdExpression evaluates to, creating or replacing the document.

fun upsert(collectionPath: String, documentIdExpression: Expression): Pipeline

Writes each document of the previous stages to the collection at collectionPath, with the id documentIdExpression evaluates to, creating or replacing the document.

Link copied to clipboard

Keeps the documents for which condition is true.