Class PipelineSource

java.lang.Object
com.google.cloud.firestore.PipelineSource

public final class PipelineSource extends Object
A 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
 
  • Method Details

    • collection

      @Nonnull public Pipeline collection(@Nonnull String path)
      Creates a new Pipeline that operates on the specified Firestore collection.
      Parameters:
      path - The path to the Firestore collection (e.g., "users").
      Returns:
      A new Pipeline instance targeting the specified collection.
    • collection

      @Nonnull public Pipeline collection(@Nonnull String path, CollectionOptions options)
    • collection

      @Nonnull public Pipeline collection(@Nonnull CollectionReference ref)
    • collectionGroup

      @Nonnull public Pipeline collectionGroup(@Nonnull 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.

      Parameters:
      collectionId - The ID of the collection group.
      Returns:
      A new Pipeline instance targeting the specified collection group.
    • collectionGroup

      @Nonnull public Pipeline collectionGroup(@Nonnull String collectionId, CollectionGroupOptions options)
    • database

      @Nonnull 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:
      A new Pipeline instance targeting all documents in the database.
    • documents

      @Nonnull public Pipeline documents(DocumentReference... docs)
      Creates a new Pipeline that operates on a specific set of Firestore documents.
      Parameters:
      docs - The DocumentReference instances representing the documents to include in the pipeline.
      Returns:
      A new Pipeline instance targeting the specified documents.
    • documents

      @Nonnull public Pipeline documents(String... docs)
      Creates a new Pipeline that operates on a specific set of Firestore documents.
      Parameters:
      docs - The DocumentReference instances representing the documents to include in the pipeline.
      Returns:
      A new Pipeline instance targeting the specified documents.
    • literals

      @Nonnull 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();
       
      Parameters:
      data - The Maps representing documents to include in the pipeline.
      Returns:
      A new Pipeline instance with a literals source.
    • createFrom

      @Nonnull 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.
      Parameters:
      query - The Query to translate into the resulting pipeline.
      Returns:
      A new Pipeline that is equivalent to the given query.
    • createFrom

      @Nonnull 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.
      Parameters:
      query - The AggregateQuery to translate into the resulting pipeline.
      Returns:
      A new Pipeline that is equivalent to the given query.
    • subcollection

      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"));
       
      Parameters:
      path - The path of the subcollection.
      Returns:
      A new Pipeline instance scoped to the subcollection.