public final class PipelineSourceA factory for creating Pipeline instances, which provide a framework for building data transformation and query pipelines for Firestore.
Start by calling Firestore#pipeline() to obtain an instance of PipelineSource.
From there, you can use the provided methods (like #collection(String)) to specify the
data source for your pipeline.
This class is typically used to start building Firestore pipelines. It allows you to define the initial data source for a pipeline.
Example Usage:
firestore.pipeline() // Get a PipelineSource instance
.collection("users") // Create a pipeline that operates on a collection
.select("name"); // Add stages to the pipeline
Static Methods
subcollection(String path)
public static Pipeline subcollection(String path)Initializes a pipeline scoped to a subcollection.
This method allows you to start a new pipeline that operates on a subcollection of the current document. It is intended to be used as a subquery.
Note: A pipeline created with subcollection cannot be executed directly using
Pipeline#execute(). It must be used within a parent pipeline.
Example:
firestore.pipeline().collection("books")
.addFields(
PipelineSource.subcollection("reviews")
.aggregate(AggregateFunction.average("rating").as("avg_rating"))
.toScalarExpression().as("average_rating"));
| Parameter | |
|---|---|
| Name | Description |
path |
StringThe path of the subcollection. |
| Returns | |
|---|---|
| Type | Description |
Pipeline |
A new |
Methods
collection(CollectionReference ref)
public Pipeline collection(CollectionReference ref)| Parameter | |
|---|---|
| Name | Description |
ref |
CollectionReference |
| Returns | |
|---|---|
| Type | Description |
Pipeline |
|
collection(String path)
public Pipeline collection(String path)Creates a new Pipeline that operates on the specified Firestore collection.
| Parameter | |
|---|---|
| Name | Description |
path |
StringThe path to the Firestore collection (e.g., "users"). |
| Returns | |
|---|---|
| Type | Description |
Pipeline |
A new |
collection(String path, CollectionOptions options)
public Pipeline collection(String path, CollectionOptions options)| Parameters | |
|---|---|
| Name | Description |
path |
String |
options |
CollectionOptions |
| Returns | |
|---|---|
| Type | Description |
Pipeline |
|
collectionGroup(String collectionId)
public Pipeline collectionGroup(String collectionId)Creates a new Pipeline that operates on all documents in a collection group.
A collection group consists of all collections with the same ID. For example, if you have collections named "users" under different documents, you can query them together using a collection group query.
| Parameter | |
|---|---|
| Name | Description |
collectionId |
StringThe ID of the collection group. |
| Returns | |
|---|---|
| Type | Description |
Pipeline |
A new |
collectionGroup(String collectionId, CollectionGroupOptions options)
public Pipeline collectionGroup(String collectionId, CollectionGroupOptions options)| Parameters | |
|---|---|
| Name | Description |
collectionId |
String |
options |
CollectionGroupOptions |
| Returns | |
|---|---|
| Type | Description |
Pipeline |
|
createFrom(AggregateQuery query)
public Pipeline createFrom(AggregateQuery query)Creates a new Pipeline from the given AggregateQuery. Under the hood, this will translate the query semantics (order by document ID, etc.) to an equivalent pipeline.
| Parameter | |
|---|---|
| Name | Description |
query |
AggregateQueryThe AggregateQuery to translate into the resulting pipeline. |
| Returns | |
|---|---|
| Type | Description |
Pipeline |
A new |
createFrom(Query query)
public Pipeline createFrom(Query query)Creates a new Pipeline from the given Query. Under the hood, this will translate the query semantics (order by document ID, etc.) to an equivalent pipeline.
| Parameter | |
|---|---|
| Name | Description |
query |
QueryThe Query to translate into the resulting pipeline. |
| Returns | |
|---|---|
| Type | Description |
Pipeline |
A new |
database()
public Pipeline database()Creates a new Pipeline that operates on all documents in the Firestore database.
Use this method with caution as it can lead to very large result sets. It is usually only useful at development stage.
| Returns | |
|---|---|
| Type | Description |
Pipeline |
A new |
documents(DocumentReference[] docs)
public Pipeline documents(DocumentReference[] docs)Creates a new Pipeline that operates on a specific set of Firestore documents.
| Parameter | |
|---|---|
| Name | Description |
docs |
DocumentReference[]The DocumentReference instances representing the documents to include in the pipeline. |
| Returns | |
|---|---|
| Type | Description |
Pipeline |
A new |
documents(String[] docs)
public Pipeline documents(String[] docs)Creates a new Pipeline that operates on a specific set of Firestore documents.
| Parameter | |
|---|---|
| Name | Description |
docs |
String[]The DocumentReference instances representing the documents to include in the pipeline. |
| Returns | |
|---|---|
| Type | Description |
Pipeline |
A new |
literals(Map<String,Object>[] data)
public final Pipeline literals(Map<String,Object>[] data)Creates a new Pipeline that operates on a static set of documents represented as Maps.
Example:
Map<String, Object> doc1 = new HashMap<>();
doc1.put("title", "Book 1");
Map<String, Object> doc2 = new HashMap<>();
doc2.put("title", "Book 2");
Snapshot snapshot = firestore.pipeline()
.literals(doc1, doc2)
.execute()
.get();
| Parameter | |
|---|---|
| Name | Description |
data |
Map<String,Object>[]The Maps representing documents to include in the pipeline. |
| Returns | |
|---|---|
| Type | Description |
Pipeline |
A new |