4.6.0 (latest) 4.5.0 4.4.0 4.3.0 4.2.0 4.1.0 4.0.0 3.13.0 3.12.0 3.11.0 3.10.0 3.9.0 3.8.0 3.7.0 3.6.0 3.5.1 3.4.0 3.3.0 3.2.0 3.1.0 3.0.0 2.5.0 2.4.0 2.3.1

    public sealed class CollectionReference : Query, IEquatable<Query>, IEquatable<CollectionReference>, IComparable<CollectionReference>

Reference documentation and code samples for the Firestore API class CollectionReference.

A reference to a collection in a Firestore database. The existence of
this object does not imply that the collection currently exists in storage.

## Inheritance

[object](https://learn.microsoft.com/dotnet/api/system.object) \> [Query](https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.Firestore/latest/Google.Cloud.Firestore.Query) \> CollectionReference

## Implements

[IEquatable](https://learn.microsoft.com/dotnet/api/system.iequatable-1)[Query](https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.Firestore/latest/Google.Cloud.Firestore.Query), [IEquatable](https://learn.microsoft.com/dotnet/api/system.iequatable-1)[CollectionReference](https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.Firestore/latest/Google.Cloud.Firestore.CollectionReference), [IComparable](https://learn.microsoft.com/dotnet/api/system.icomparable-1)[CollectionReference](https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.Firestore/latest/Google.Cloud.Firestore.CollectionReference)

## Inherited Members

[Query.Database](https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.Firestore/latest/Google.Cloud.Firestore.Query#Google_Cloud_Firestore_Query_Database) [Query.Select(params string\[\])](https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.Firestore/latest/Google.Cloud.Firestore.Query#Google_Cloud_Firestore_Query_Select_System_String___) [Query.Select(params FieldPath\[\])](https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.Firestore/latest/Google.Cloud.Firestore.Query#Google_Cloud_Firestore_Query_Select_Google_Cloud_Firestore_FieldPath___) [Query.WhereEqualTo(string, object)](https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.Firestore/latest/Google.Cloud.Firestore.Query#Google_Cloud_Firestore_Query_WhereEqualTo_System_String_System_Object_) [Query.WhereEqualTo(FieldPath, object)](https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.Firestore/latest/Google.Cloud.Firestore.Query#Google_Cloud_Firestore_Query_WhereEqualTo_Google_Cloud_Firestore_FieldPath_System_Object_) [Query.WhereNotEqualTo(string, object)](https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.Firestore/latest/Google.Cloud.Firestore.Query#Google_Cloud_Firestore_Query_WhereNotEqualTo_System_String_System_Object_) [Query.WhereNotEqualTo(FieldPath, object)](https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.Firestore/latest/Google.Cloud.Firestore.Query#Google_Cloud_Firestore_Query_WhereNotEqualTo_Google_Cloud_Firestore_FieldPath_System_Object_) [Query.WhereLessThan(string, object)](https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.Firestore/latest/Google.Cloud.Firestore.Query#Google_Cloud_Firestore_Query_WhereLessThan_System_String_System_Object_) [Query.WhereLessThan(FieldPath, object)](https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.Firestore/latest/Google.Cloud.Firestore.Query#Google_Cloud_Firestore_Query_WhereLessThan_Google_Cloud_Firestore_FieldPath_System_Object_) [Query.WhereLessThanOrEqualTo(string, object)](https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.Firestore/latest/Google.Cloud.Firestore.Query#Google_Cloud_Firestore_Query_WhereLessThanOrEqualTo_System_String_System_Object_) [Query.WhereLessThanOrEqualTo(FieldPath, object)](https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.Firestore/latest/Google.Cloud.Firestore.Query#Google_Cloud_Firestore_Query_WhereLessThanOrEqualTo_Google_Cloud_Firestore_FieldPath_System_Object_) [Query.WhereGreaterThan(string, object)](https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.Firestore/latest/Google.Cloud.Firestore.Query#Google_Cloud_Firestore_Query_WhereGreaterThan_System_String_System_Object_) [Query.WhereGreaterThan(FieldPath, object)](https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.Firestore/latest/Google.Cloud.Firestore.Query#Google_Cloud_Firestore_Query_WhereGreaterThan_Google_Cloud_Firestore_FieldPath_System_Object_) [Query.WhereGreaterThanOrEqualTo(string, object)](https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.Firestore/latest/Google.Cloud.Firestore.Query#Google_Cloud_Firestore_Query_WhereGreaterThanOrEqualTo_System_String_System_Object_) [Query.WhereGreaterThanOrEqualTo(FieldPath, object)](https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.Firestore/latest/Google.Cloud.Firestore.Query#Google_Cloud_Firestore_Query_WhereGreaterThanOrEqualTo_Google_Cloud_Firestore_FieldPath_System_Object_) [Query.WhereArrayContains(string, object)](https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.Firestore/latest/Google.Cloud.Firestore.Query#Google_Cloud_Firestore_Query_WhereArrayContains_System_String_System_Object_) [Query.WhereArrayContains(FieldPath, object)](https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.Firestore/latest/Google.Cloud.Firestore.Query#Google_Cloud_Firestore_Query_WhereArrayContains_Google_Cloud_Firestore_FieldPath_System_Object_) [Query.WhereArrayContainsAny(string, IEnumerable)](https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.Firestore/latest/Google.Cloud.Firestore.Query#Google_Cloud_Firestore_Query_WhereArrayContainsAny_System_String_System_Collections_IEnumerable_) [Query.WhereArrayContainsAny(FieldPath, IEnumerable)](https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.Firestore/latest/Google.Cloud.Firestore.Query#Google_Cloud_Firestore_Query_WhereArrayContainsAny_Google_Cloud_Firestore_FieldPath_System_Collections_IEnumerable_) [Query.WhereIn(string, IEnumerable)](https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.Firestore/latest/Google.Cloud.Firestore.Query#Google_Cloud_Firestore_Query_WhereIn_System_String_System_Collections_IEnumerable_) [Query.WhereIn(FieldPath, IEnumerable)](https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.Firestore/latest/Google.Cloud.Firestore.Query#Google_Cloud_Firestore_Query_WhereIn_Google_Cloud_Firestore_FieldPath_System_Collections_IEnumerable_) [Query.WhereNotIn(string, IEnumerable)](https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.Firestore/latest/Google.Cloud.Firestore.Query#Google_Cloud_Firestore_Query_WhereNotIn_System_String_System_Collections_IEnumerable_) [Query.WhereNotIn(FieldPath, IEnumerable)](https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.Firestore/latest/Google.Cloud.Firestore.Query#Google_Cloud_Firestore_Query_WhereNotIn_Google_Cloud_Firestore_FieldPath_System_Collections_IEnumerable_) [Query.Count()](https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.Firestore/latest/Google.Cloud.Firestore.Query#Google_Cloud_Firestore_Query_Count) [Query.Aggregate(AggregateField, params AggregateField\[\])](https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.Firestore/latest/Google.Cloud.Firestore.Query#Google_Cloud_Firestore_Query_Aggregate_Google_Cloud_Firestore_AggregateField_Google_Cloud_Firestore_AggregateField___) [Query.Aggregate(IEnumerable\<AggregateField\>)](https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.Firestore/latest/Google.Cloud.Firestore.Query#Google_Cloud_Firestore_Query_Aggregate_System_Collections_Generic_IEnumerable_Google_Cloud_Firestore_AggregateField__) [Query.Where(Filter)](https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.Firestore/latest/Google.Cloud.Firestore.Query#Google_Cloud_Firestore_Query_Where_Google_Cloud_Firestore_Filter_) [Query.OrderBy(string)](https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.Firestore/latest/Google.Cloud.Firestore.Query#Google_Cloud_Firestore_Query_OrderBy_System_String_) [Query.OrderByDescending(string)](https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.Firestore/latest/Google.Cloud.Firestore.Query#Google_Cloud_Firestore_Query_OrderByDescending_System_String_) [Query.OrderBy(FieldPath)](https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.Firestore/latest/Google.Cloud.Firestore.Query#Google_Cloud_Firestore_Query_OrderBy_Google_Cloud_Firestore_FieldPath_) [Query.OrderByDescending(FieldPath)](https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.Firestore/latest/Google.Cloud.Firestore.Query#Google_Cloud_Firestore_Query_OrderByDescending_Google_Cloud_Firestore_FieldPath_) [Query.Limit(int)](https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.Firestore/latest/Google.Cloud.Firestore.Query#Google_Cloud_Firestore_Query_Limit_System_Int32_) [Query.LimitToLast(int)](https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.Firestore/latest/Google.Cloud.Firestore.Query#Google_Cloud_Firestore_Query_LimitToLast_System_Int32_) [Query.Offset(int)](https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.Firestore/latest/Google.Cloud.Firestore.Query#Google_Cloud_Firestore_Query_Offset_System_Int32_) [Query.StartAt(params object\[\])](https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.Firestore/latest/Google.Cloud.Firestore.Query#Google_Cloud_Firestore_Query_StartAt_System_Object___) [Query.StartAfter(params object\[\])](https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.Firestore/latest/Google.Cloud.Firestore.Query#Google_Cloud_Firestore_Query_StartAfter_System_Object___) [Query.EndBefore(params object\[\])](https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.Firestore/latest/Google.Cloud.Firestore.Query#Google_Cloud_Firestore_Query_EndBefore_System_Object___) [Query.EndAt(params object\[\])](https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.Firestore/latest/Google.Cloud.Firestore.Query#Google_Cloud_Firestore_Query_EndAt_System_Object___) [Query.StartAt(DocumentSnapshot)](https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.Firestore/latest/Google.Cloud.Firestore.Query#Google_Cloud_Firestore_Query_StartAt_Google_Cloud_Firestore_DocumentSnapshot_) [Query.StartAfter(DocumentSnapshot)](https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.Firestore/latest/Google.Cloud.Firestore.Query#Google_Cloud_Firestore_Query_StartAfter_Google_Cloud_Firestore_DocumentSnapshot_) [Query.EndBefore(DocumentSnapshot)](https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.Firestore/latest/Google.Cloud.Firestore.Query#Google_Cloud_Firestore_Query_EndBefore_Google_Cloud_Firestore_DocumentSnapshot_) [Query.EndAt(DocumentSnapshot)](https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.Firestore/latest/Google.Cloud.Firestore.Query#Google_Cloud_Firestore_Query_EndAt_Google_Cloud_Firestore_DocumentSnapshot_) [Query.GetSnapshotAsync(CancellationToken)](https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.Firestore/latest/Google.Cloud.Firestore.Query#Google_Cloud_Firestore_Query_GetSnapshotAsync_System_Threading_CancellationToken_) [Query.ExplainAsync(ExplainOptions, CancellationToken)](https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.Firestore/latest/Google.Cloud.Firestore.Query#Google_Cloud_Firestore_Query_ExplainAsync_Google_Cloud_Firestore_ExplainOptions_System_Threading_CancellationToken_) [Query.StreamAsync(CancellationToken)](https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.Firestore/latest/Google.Cloud.Firestore.Query#Google_Cloud_Firestore_Query_StreamAsync_System_Threading_CancellationToken_) [Query.Listen(Func\<QuerySnapshot, CancellationToken, Task\>, CancellationToken)](https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.Firestore/latest/Google.Cloud.Firestore.Query#Google_Cloud_Firestore_Query_Listen_System_Func_Google_Cloud_Firestore_QuerySnapshot_System_Threading_CancellationToken_System_Threading_Tasks_Task__System_Threading_CancellationToken_) [Query.Listen(Action\<QuerySnapshot\>, CancellationToken)](https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.Firestore/latest/Google.Cloud.Firestore.Query#Google_Cloud_Firestore_Query_Listen_System_Action_Google_Cloud_Firestore_QuerySnapshot__System_Threading_CancellationToken_) [object.GetType()](https://learn.microsoft.com/dotnet/api/system.object.gettype)

## Namespace

[Google.Cloud.Firestore](https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.Firestore/latest/Google.Cloud.Firestore)

## Assembly

Google.Cloud.Firestore.dll

## Properties

### Id

    public string Id { get; }

The final part of the complete collection path; this is the identity of
the collection relative to its parent document.

| **Property Value** ||
|---|---|
| **Type** | **Description** |
| `https://learn.microsoft.com/dotnet/api/system.string` |   |

### Parent

    public DocumentReference Parent { get; }

The parent document, or null if this is a root collection.

| **Property Value** ||
|---|---|
| **Type** | **Description** |
| `https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.Firestore/latest/Google.Cloud.Firestore.DocumentReference` |   |

### Path

    public string Path { get; }

The complete collection path, including project and database ID.

| **Property Value** ||
|---|---|
| **Type** | **Description** |
| `https://learn.microsoft.com/dotnet/api/system.string` |   |

## Methods

### AddAsync(object, CancellationToken)

    public Task<DocumentReference> AddAsync(object documentData, CancellationToken cancellationToken = default)

Asynchronously creates a document with the given data in this collection. The document has a randomly generated ID.

| **Parameters** ||
|---|---|
| **Name** | **Description** |
| `documentData` | `https://learn.microsoft.com/dotnet/api/system.object` The data for the document. Must not be null. |
| `cancellationToken` | `https://learn.microsoft.com/dotnet/api/system.threading.cancellationtoken` A cancellation token to monitor for the asynchronous operation. |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://learn.microsoft.com/dotnet/api/system.threading.tasks.task-1https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.Firestore/latest/Google.Cloud.Firestore.DocumentReference` | The reference for the newly-created document. |

**Remarks** If the [WriteResult](https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.Firestore/latest/Google.Cloud.Firestore.WriteResult) for the operation is required, use [CreateAsync(object, CancellationToken)](https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.Firestore/latest/Google.Cloud.Firestore.DocumentReference#Google_Cloud_Firestore_DocumentReference_CreateAsync_System_Object_System_Threading_CancellationToken_)
instead of this method.

### CompareTo(CollectionReference)

    public int CompareTo(CollectionReference other)

| **Parameter** ||
|---|---|
| **Name** | **Description** |
| `other` | `https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.Firestore/latest/Google.Cloud.Firestore.CollectionReference` |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://learn.microsoft.com/dotnet/api/system.int32` |   |

### Document()

    public DocumentReference Document()

Creates a [DocumentReference](https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.Firestore/latest/Google.Cloud.Firestore.DocumentReference) for a direct child document of this collection with a random ID.
This performs no server-side operations; it only generates the appropriate `DocumentReference`.

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.Firestore/latest/Google.Cloud.Firestore.DocumentReference` | A [DocumentReference](https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.Firestore/latest/Google.Cloud.Firestore.DocumentReference) to a child document of this collection with a random ID. |

### Document(string)

    public DocumentReference Document(string path)

Creates a [DocumentReference](https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.Firestore/latest/Google.Cloud.Firestore.DocumentReference) for a child document of this reference.

| **Parameter** ||
|---|---|
| **Name** | **Description** |
| `path` | `https://learn.microsoft.com/dotnet/api/system.string` The path to the document, relative to this collection. Must not be null, and must contain an odd number of slash-separated path elements. |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.Firestore/latest/Google.Cloud.Firestore.DocumentReference` | A [DocumentReference](https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.Firestore/latest/Google.Cloud.Firestore.DocumentReference) for the specified document. |

### GetHashCode()

    public override int GetHashCode()

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://learn.microsoft.com/dotnet/api/system.int32` |   |

**Overrides** [Query.GetHashCode()](https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.Firestore/latest/Google.Cloud.Firestore.Query#Google_Cloud_Firestore_Query_GetHashCode)

### ListDocumentsAsync()

    public IAsyncEnumerable<DocumentReference> ListDocumentsAsync()

Lists the documents in this collection. The results include documents which don't exist in their own right, but which have
nested documents which do exist.

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://learn.microsoft.com/dotnet/api/system.collections.generic.iasyncenumerable-1https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.Firestore/latest/Google.Cloud.Firestore.DocumentReference` | A lazily-iterated sequence of document references within this collection. |

### ToString()

    public override string ToString()

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://learn.microsoft.com/dotnet/api/system.string` |   |

**Overrides** [object.ToString()](https://learn.microsoft.com/dotnet/api/system.object.tostring)