Pipeline class

A query made of an ordered list of stages, executed by the server.

Start one with firestore.pipeline() and a source such as collection('books'), then add stages. A pipeline is immutable: every stage method returns a new pipeline.

final snapshot = await firestore
    .pipeline()
    .collection('books')
    .where(field('rating').greaterThan(4))
    .sort([field('rating').descending()])
    .limit(10)
    .execute();

Pipelines need a Firestore Enterprise edition database. They are always executed by the server: they do not read or update the local cache, do not see pending writes, fail with unavailable while offline and cannot be listened to.

Every stage accepts rawOptions, named options sent to the server as they are, for options this SDK has no parameter for yet.

Preview, Enterprise only: the Pipelines API is experimental, may change in any release and needs a Firestore Enterprise edition database.

Properties

firestore → FirebaseFirestore
The database this pipeline runs against.
final
hashCode → int
The hash code for this object.
no setterinherited
runtimeType → Type
A representation of the runtime type of the object.
no setterinherited

Methods

addFields(List<Selectable> fields, {Map<String, Object?>? rawOptions}) → Pipeline
Adds the given aliased expressions as fields to every input, keeping the existing fields.
addWindowFields(WindowSpec window, List<Object> fields, {Map<String, Object?>? rawOptions}) → Pipeline
Adds the results of window functions to every input, keeping the existing fields and the number of inputs.
aggregate(List<AliasedAggregate> accumulators, {List<Object> groups = const <Object>[], Map<String, Object?>? rawOptions}) → Pipeline
Combines the inputs into one result per group, computing accumulators for each.
define(List<AliasedExpression> variables, {Map<String, Object?>? rawOptions}) → Pipeline
Defines variables for the following stages and for subqueries used in them: every aliased expression becomes the variable with that name, read with variable(name).
delete({Map<String, Object?>? rawOptions}) → Pipeline
Deletes every input document. The result of the pipeline is one row with the number of documents_modified.
distinct(List<Object> groups, {Map<String, Object?>? rawOptions}) → Pipeline
Outputs one result for every distinct combination of groups: field names (String), Fields or aliased expressions.
execute({bool atomic = false, PipelineIndexMode? indexMode, PipelineExplainOptions? explainOptions, Map<String, Object?>? rawOptions}) → Future<PipelineSnapshot>
Executes this pipeline on the server.
findNearest(Object field, Object vector, DistanceMeasure distanceMeasure, {int? limit, String? distanceField, Map<String, Object?>? rawOptions}) → Pipeline
Keeps the inputs whose vector field (a String name or a Field) is nearest to vector (a VectorValue, a List<double> or an Expression), nearest first.
insert({Object? collection, Object? documentId, Map<String, Object?>? rawOptions}) → Pipeline
Creates a document from every input; fails with already-exists if one of them exists.
limit(int limit, {Map<String, Object?>? rawOptions}) → Pipeline
Keeps at most the first limit inputs.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
offset(int offset, {Map<String, Object?>? rawOptions}) → Pipeline
Skips the first offset inputs.
rawStage(String name, List<Object?> args, {Map<String, Object?>? options}) → Pipeline
Adds a stage this SDK has no method for: name is the server name of the stage (snake case), args its positional arguments (values or Expressions) and options its named options.
removeFields(List<Object> fields, {Map<String, Object?>? rawOptions}) → Pipeline
Removes the given fields (String names or Fields) from every input.
replaceWith(Object fieldOrExpression, {Map<String, Object?>? rawOptions}) → Pipeline
Replaces every input with the map that fieldOrExpression evaluates to: a field name (String) or an Expression.
sample({int? documents, double? percentage, Map<String, Object?>? rawOptions}) → Pipeline
Keeps a random sample of the inputs: either a number of documents, or a percentage of them between 0 and 1. Exactly one must be given.
Keeps the documents that match query, a full-text or geo search, and orders them by relevance or by sort.
select(List<Object> selections, {Map<String, Object?>? rawOptions}) → Pipeline
Outputs only the given selections: field names (String), Fields or expressions with an alias (field('a').add(1).as('b')).
sort(List<Ordering> orderings, {Map<String, Object?>? rawOptions}) → Pipeline
Sorts the inputs by orderings, the first one being the most significant.
toArrayExpression() → Expression
This pipeline as an expression that evaluates to the array of its results, for use in a stage of another pipeline (a subquery).
toScalarExpression() → Expression
This pipeline as an expression that evaluates to its single result, for use in a stage of another pipeline (a subquery). The pipeline must produce at most one result; with a single output field the expression is the value of that field.
toString() → String
A string representation of this object.
override
union(Pipeline other, {Map<String, Object?>? rawOptions}) → Pipeline
Appends the results of other to the results of this pipeline. The order of the combined results is not defined.
unnest(Selectable selectable, {String? indexField, Map<String, Object?>? rawOptions}) → Pipeline
Outputs one result per element of an array: selectable is the array expression with the alias under which each element is stored (field('tags').as('tag')).
update({List<Selectable> transformedFields = const <Selectable>[], Map<String, Object?>? rawOptions}) → Pipeline
Writes every input document back to where it was read from.
upsert({List<Selectable> additionalFields = const <Selectable>[], Object? collection, Object? documentId, Map<String, Object?>? rawOptions}) → Pipeline
Creates or replaces a document from every input.
where(BooleanExpression condition, {Map<String, Object?>? rawOptions}) → Pipeline
Keeps only the inputs for which condition holds.

Operators

operator ==(Object other) → bool
The equality operator.
inherited