# PipelineSource


```
class PipelineSource
```

<br />

*** ** * ** ***

Start of a Firestore Pipeline

## Summary

| ### Public companion functions |
|---|---|
| `https://firebase.google.com/docs/reference/kotlin/com/google/firebase/firestore/Pipeline` | `https://firebase.google.com/docs/reference/kotlin/com/google/firebase/firestore/PipelineSource#subcollection(kotlin.String)(path: https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html)` Initializes a pipeline scoped to a subcollection. |
| `https://firebase.google.com/docs/reference/kotlin/com/google/firebase/firestore/Pipeline` | `https://firebase.google.com/docs/reference/kotlin/com/google/firebase/firestore/PipelineSource#subcollection(com.google.firebase.firestore.pipeline.SubcollectionSource)(source: https://firebase.google.com/docs/reference/kotlin/com/google/firebase/firestore/pipeline/SubcollectionSource)` Creates a pipeline that processes the documents in the specified subcollection of the current document. |

| ### Public functions |
|---|---|
| `https://firebase.google.com/docs/reference/kotlin/com/google/firebase/firestore/Pipeline` | `https://firebase.google.com/docs/reference/kotlin/com/google/firebase/firestore/PipelineSource#collection(kotlin.String)(path: https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html)` Set the pipeline's source to the collection specified by the given path. |
| `https://firebase.google.com/docs/reference/kotlin/com/google/firebase/firestore/Pipeline` | `https://firebase.google.com/docs/reference/kotlin/com/google/firebase/firestore/PipelineSource#collection(com.google.firebase.firestore.CollectionReference)(ref: https://firebase.google.com/docs/reference/kotlin/com/google/firebase/firestore/CollectionReference)` Set the pipeline's source to the collection specified by the given `https://firebase.google.com/docs/reference/kotlin/com/google/firebase/firestore/CollectionReference`. |
| `https://firebase.google.com/docs/reference/kotlin/com/google/firebase/firestore/Pipeline` | `https://firebase.google.com/docs/reference/kotlin/com/google/firebase/firestore/PipelineSource#collection(com.google.firebase.firestore.CollectionReference,com.google.firebase.firestore.pipeline.CollectionSourceOptions)(ref: https://firebase.google.com/docs/reference/kotlin/com/google/firebase/firestore/CollectionReference, options: https://firebase.google.com/docs/reference/kotlin/com/google/firebase/firestore/pipeline/CollectionSourceOptions)` Set the pipeline's source to the collection specified by the given `https://firebase.google.com/docs/reference/kotlin/com/google/firebase/firestore/CollectionReference`. |
| `https://firebase.google.com/docs/reference/kotlin/com/google/firebase/firestore/Pipeline` | `https://firebase.google.com/docs/reference/kotlin/com/google/firebase/firestore/PipelineSource#collectionGroup(kotlin.String)(collectionId: https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html)` Set the pipeline's source to the collection group with the given id. |
| `https://firebase.google.com/docs/reference/kotlin/com/google/firebase/firestore/Pipeline` | `https://firebase.google.com/docs/reference/kotlin/com/google/firebase/firestore/PipelineSource#collectionGroup(kotlin.String,com.google.firebase.firestore.pipeline.CollectionGroupOptions)(collectionId: https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html, options: https://firebase.google.com/docs/reference/kotlin/com/google/firebase/firestore/pipeline/CollectionGroupOptions)` Set the pipeline's source to the collection group with the given id. |
| `https://firebase.google.com/docs/reference/kotlin/com/google/firebase/firestore/Pipeline` | `https://firebase.google.com/docs/reference/kotlin/com/google/firebase/firestore/PipelineSource#createFrom(com.google.firebase.firestore.AggregateQuery)(aggregateQuery: https://firebase.google.com/docs/reference/kotlin/com/google/firebase/firestore/AggregateQuery)` Convert the given Aggregate Query into an equivalent Pipeline. |
| `https://firebase.google.com/docs/reference/kotlin/com/google/firebase/firestore/Pipeline` | `https://firebase.google.com/docs/reference/kotlin/com/google/firebase/firestore/PipelineSource#createFrom(com.google.firebase.firestore.Query)(query: https://firebase.google.com/docs/reference/kotlin/com/google/firebase/firestore/Query)` Convert the given Query into an equivalent Pipeline. |
| `https://firebase.google.com/docs/reference/kotlin/com/google/firebase/firestore/Pipeline` | `https://firebase.google.com/docs/reference/kotlin/com/google/firebase/firestore/PipelineSource#database()()` Set the pipeline's source to be all documents in this database. |
| `https://firebase.google.com/docs/reference/kotlin/com/google/firebase/firestore/Pipeline` | `https://firebase.google.com/docs/reference/kotlin/com/google/firebase/firestore/PipelineSource#documents(kotlin.Array)(vararg documents: https://firebase.google.com/docs/reference/kotlin/com/google/firebase/firestore/DocumentReference)` Set the pipeline's source to the documents specified by the given DocumentReferences. |
| `https://firebase.google.com/docs/reference/kotlin/com/google/firebase/firestore/Pipeline` | `https://firebase.google.com/docs/reference/kotlin/com/google/firebase/firestore/PipelineSource#documents(kotlin.Array)(vararg documents: https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html)` Set the pipeline's source to the documents specified by the given paths. |
| `https://firebase.google.com/docs/reference/kotlin/com/google/firebase/firestore/Pipeline` | `https://firebase.google.com/docs/reference/kotlin/com/google/firebase/firestore/PipelineSource#literals(kotlin.Array)(vararg data: https://kotlinlang.org/api/latest/jvm/stdlib/kotlin.collections/-map/index.html<https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html, https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-any/index.html?>)` Sets the pipeline's source to the given literal documents. |

## Public companion functions

### subcollection

```
fun subcollection(path: String): Pipeline
```

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. It must be used within a parent pipeline.

Example:

```kotlin
firestore.pipeline().collection("books")
    .addFields(
        PipelineSource.subcollection("reviews")
            .aggregate(AggregateFunction.average("rating").as("avg_rating"))
            .toScalarExpression().as("average_rating"))
```

| Parameters |
|---|---|
| `path: https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html` | The path of the subcollection. |

| Returns |
|---|---|
| `https://firebase.google.com/docs/reference/kotlin/com/google/firebase/firestore/Pipeline` | A new `https://firebase.google.com/docs/reference/kotlin/com/google/firebase/firestore/Pipeline` instance scoped to the subcollection. |

### subcollection

```
fun subcollection(source: SubcollectionSource): Pipeline
```

Creates a pipeline that processes the documents in the specified subcollection of the current document.

Example:

```kotlin
firestore.pipeline().collection("books")
    .addFields(
        PipelineSource.subcollection(SubcollectionSource.of("reviews"))
            .aggregate(AggregateFunction.average("rating").as("avg_rating"))
            .toScalarExpression().as("average_rating"))
```

| Parameters |
|---|---|
| `source: https://firebase.google.com/docs/reference/kotlin/com/google/firebase/firestore/pipeline/SubcollectionSource` | The subcollection that will be the source of this pipeline. |

| Returns |
|---|---|
| `https://firebase.google.com/docs/reference/kotlin/com/google/firebase/firestore/Pipeline` | A new `https://firebase.google.com/docs/reference/kotlin/com/google/firebase/firestore/Pipeline` scoped to the subcollection. |

## Public functions

### collection

```
fun collection(path: String): Pipeline
```

Set the pipeline's source to the collection specified by the given path.

| Parameters |
|---|---|
| `path: https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html` | A path to a collection that will be the source of this pipeline. |

| Returns |
|---|---|
| `https://firebase.google.com/docs/reference/kotlin/com/google/firebase/firestore/Pipeline` | A new `https://firebase.google.com/docs/reference/kotlin/com/google/firebase/firestore/Pipeline` object with documents from target collection. |

### collection

```
fun collection(ref: CollectionReference): Pipeline
```

Set the pipeline's source to the collection specified by the given `https://firebase.google.com/docs/reference/kotlin/com/google/firebase/firestore/CollectionReference`.

| Parameters |
|---|---|
| `ref: https://firebase.google.com/docs/reference/kotlin/com/google/firebase/firestore/CollectionReference` | A `https://firebase.google.com/docs/reference/kotlin/com/google/firebase/firestore/CollectionReference` for a collection that will be the source of this pipeline. |

| Returns |
|---|---|
| `https://firebase.google.com/docs/reference/kotlin/com/google/firebase/firestore/Pipeline` | A new `https://firebase.google.com/docs/reference/kotlin/com/google/firebase/firestore/Pipeline` object with documents from target collection. |

| Throws |
|---|---|
| `java.lang.IllegalArgumentException: https://developer.android.com/reference/kotlin/java/lang/IllegalArgumentException.html` | Thrown if the `https://firebase.google.com/docs/reference/kotlin/com/google/firebase/firestore/PipelineSource#collection(com.google.firebase.firestore.CollectionReference)` provided targets a different project or database than the pipeline. |

### collection

```
fun collection(ref: CollectionReference, options: CollectionSourceOptions): Pipeline
```

Set the pipeline's source to the collection specified by the given `https://firebase.google.com/docs/reference/kotlin/com/google/firebase/firestore/CollectionReference`.

| Parameters |
|---|---|
| `ref: https://firebase.google.com/docs/reference/kotlin/com/google/firebase/firestore/CollectionReference` | A `https://firebase.google.com/docs/reference/kotlin/com/google/firebase/firestore/CollectionReference` for a collection that will be the source of this pipeline. |
| `options: https://firebase.google.com/docs/reference/kotlin/com/google/firebase/firestore/pipeline/CollectionSourceOptions` | `https://firebase.google.com/docs/reference/kotlin/com/google/firebase/firestore/pipeline/CollectionSourceOptions` for the collection. |

| Returns |
|---|---|
| `https://firebase.google.com/docs/reference/kotlin/com/google/firebase/firestore/Pipeline` | A new `https://firebase.google.com/docs/reference/kotlin/com/google/firebase/firestore/Pipeline` object with documents from target collection. |

| Throws |
|---|---|
| `java.lang.IllegalArgumentException: https://developer.android.com/reference/kotlin/java/lang/IllegalArgumentException.html` | Thrown if the `https://firebase.google.com/docs/reference/kotlin/com/google/firebase/firestore/PipelineSource#collection(com.google.firebase.firestore.CollectionReference,com.google.firebase.firestore.pipeline.CollectionSourceOptions)` provided targets a different project or database than the pipeline. |

### collectionGroup

```
fun collectionGroup(collectionId: String): Pipeline
```

Set the pipeline's source to the collection group with the given id.

| Parameters |
|---|---|
| `collectionId: https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html` | The id of a collection group that will be the source of this pipeline. |

| Returns |
|---|---|
| `https://firebase.google.com/docs/reference/kotlin/com/google/firebase/firestore/Pipeline` | A new `https://firebase.google.com/docs/reference/kotlin/com/google/firebase/firestore/Pipeline` object with documents from target collection group. |

### collectionGroup

```
fun collectionGroup(collectionId: String, options: CollectionGroupOptions): Pipeline
```

Set the pipeline's source to the collection group with the given id.

| Parameters |
|---|---|
| `collectionId: https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html` | The id of a collection group that will be the source of this pipeline. |
| `options: https://firebase.google.com/docs/reference/kotlin/com/google/firebase/firestore/pipeline/CollectionGroupOptions` | `https://firebase.google.com/docs/reference/kotlin/com/google/firebase/firestore/pipeline/CollectionGroupOptions` for the collection group. |

| Returns |
|---|---|
| `https://firebase.google.com/docs/reference/kotlin/com/google/firebase/firestore/Pipeline` | A new `https://firebase.google.com/docs/reference/kotlin/com/google/firebase/firestore/Pipeline` object with documents from target collection group. |

### createFrom

```
fun createFrom(aggregateQuery: AggregateQuery): Pipeline
```

Convert the given Aggregate Query into an equivalent Pipeline.

| Parameters |
|---|---|
| `aggregateQuery: https://firebase.google.com/docs/reference/kotlin/com/google/firebase/firestore/AggregateQuery` | An Aggregate Query to be converted into a Pipeline. |

| Returns |
|---|---|
| `https://firebase.google.com/docs/reference/kotlin/com/google/firebase/firestore/Pipeline` | A new `https://firebase.google.com/docs/reference/kotlin/com/google/firebase/firestore/Pipeline` object that is equivalent to `https://firebase.google.com/docs/reference/kotlin/com/google/firebase/firestore/PipelineSource#createFrom(com.google.firebase.firestore.AggregateQuery)` |

| Throws |
|---|---|
| `java.lang.IllegalArgumentException: https://developer.android.com/reference/kotlin/java/lang/IllegalArgumentException.html` | Thrown if the `https://firebase.google.com/docs/reference/kotlin/com/google/firebase/firestore/PipelineSource#createFrom(com.google.firebase.firestore.AggregateQuery)` provided targets a different project or database than the pipeline. |

### createFrom

```
fun createFrom(query: Query): Pipeline
```

Convert the given Query into an equivalent Pipeline.

| Parameters |
|---|---|
| `query: https://firebase.google.com/docs/reference/kotlin/com/google/firebase/firestore/Query` | A Query to be converted into a Pipeline. |

| Returns |
|---|---|
| `https://firebase.google.com/docs/reference/kotlin/com/google/firebase/firestore/Pipeline` | A new `https://firebase.google.com/docs/reference/kotlin/com/google/firebase/firestore/Pipeline` object that is equivalent to `https://firebase.google.com/docs/reference/kotlin/com/google/firebase/firestore/PipelineSource#createFrom(com.google.firebase.firestore.Query)` |

| Throws |
|---|---|
| `java.lang.IllegalArgumentException: https://developer.android.com/reference/kotlin/java/lang/IllegalArgumentException.html` | Thrown if the `https://firebase.google.com/docs/reference/kotlin/com/google/firebase/firestore/PipelineSource#createFrom(com.google.firebase.firestore.Query)` provided targets a different project or database than the pipeline. |

### database

```
fun database(): Pipeline
```

Set the pipeline's source to be all documents in this database.

| Returns |
|---|---|
| `https://firebase.google.com/docs/reference/kotlin/com/google/firebase/firestore/Pipeline` | A new `https://firebase.google.com/docs/reference/kotlin/com/google/firebase/firestore/Pipeline` object with all documents in this database. |

### documents

```
fun documents(vararg documents: DocumentReference): Pipeline
```

Set the pipeline's source to the documents specified by the given DocumentReferences.

| Parameters |
|---|---|
| `vararg documents: https://firebase.google.com/docs/reference/kotlin/com/google/firebase/firestore/DocumentReference` | DocumentReferences specifying the individual documents that will be the source of this pipeline. |

| Returns |
|---|---|
| `https://firebase.google.com/docs/reference/kotlin/com/google/firebase/firestore/Pipeline` | Pipeline with `https://firebase.google.com/docs/reference/kotlin/com/google/firebase/firestore/PipelineSource#documents(kotlin.Array)`. |

| Throws |
|---|---|
| `java.lang.IllegalArgumentException: https://developer.android.com/reference/kotlin/java/lang/IllegalArgumentException.html` | Thrown if the `https://firebase.google.com/docs/reference/kotlin/com/google/firebase/firestore/PipelineSource#documents(kotlin.Array)` provided targets a different project or database than the pipeline. |

### documents

```
fun documents(vararg documents: String): Pipeline
```

Set the pipeline's source to the documents specified by the given paths.

| Parameters |
|---|---|
| `vararg documents: https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html` | Paths specifying the individual documents that will be the source of this pipeline. |

| Returns |
|---|---|
| `https://firebase.google.com/docs/reference/kotlin/com/google/firebase/firestore/Pipeline` | A new `https://firebase.google.com/docs/reference/kotlin/com/google/firebase/firestore/Pipeline` object with `https://firebase.google.com/docs/reference/kotlin/com/google/firebase/firestore/PipelineSource#documents(kotlin.Array)`. |

### literals

```
fun literals(vararg data: Map<String, Any?>): Pipeline
```

Sets the pipeline's source to the given literal documents. Each map becomes one input document.

Field values can be constants or `https://firebase.google.com/docs/reference/kotlin/com/google/firebase/firestore/pipeline/Expression`s; expressions are evaluated, including expressions nested inside map or list values. FieldValue sentinels (for example, `FieldValue.serverTimestamp()`) are not supported; use an expression such as `currentTimestamp()` instead.

To give a document a path, for example to write it with `https://firebase.google.com/docs/reference/kotlin/com/google/firebase/firestore/Pipeline#upsert(kotlin.Array)`, set its `__name__` field to a `https://firebase.google.com/docs/reference/kotlin/com/google/firebase/firestore/DocumentReference`.

Example:

```kotlin
db.pipeline()
  .literals(mapOf("title" to "Dune"), mapOf("title" to "Emma"))
  .insert("books")
  .execute()
```

| Parameters |
|---|---|
| `vararg data: https://kotlinlang.org/api/latest/jvm/stdlib/kotlin.collections/-map/index.html<https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html, https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-any/index.html?>` | The documents to use as the source. At least one document is required; a pipeline without literal documents fails when it is executed. |

| Returns |
|---|---|
| `https://firebase.google.com/docs/reference/kotlin/com/google/firebase/firestore/Pipeline` | A new `https://firebase.google.com/docs/reference/kotlin/com/google/firebase/firestore/Pipeline` object with the literal documents as its source. |