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 FirestoreDb

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

A Firestore database. Create instances using the static [Create(string, FirestoreClient)](https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.Firestore/latest/Google.Cloud.Firestore.FirestoreDb#Google_Cloud_Firestore_FirestoreDb_Create_System_String_Google_Cloud_Firestore_V1_FirestoreClient_) and [CreateAsync(string, FirestoreClient)](https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.Firestore/latest/Google.Cloud.Firestore.FirestoreDb#Google_Cloud_Firestore_FirestoreDb_CreateAsync_System_String_Google_Cloud_Firestore_V1_FirestoreClient_)
methods, or using a [FirestoreDbBuilder](https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.Firestore/latest/Google.Cloud.Firestore.FirestoreDbBuilder).

## Inheritance

[object](https://learn.microsoft.com/dotnet/api/system.object) \> FirestoreDb

## Inherited Members

[object.GetHashCode()](https://learn.microsoft.com/dotnet/api/system.object.gethashcode) [object.GetType()](https://learn.microsoft.com/dotnet/api/system.object.gettype) [object.ToString()](https://learn.microsoft.com/dotnet/api/system.object.tostring)

## 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

### Client

    public FirestoreClient Client { get; }

The underlying client used to make service requests.

| **Property Value** ||
|---|---|
| **Type** | **Description** |
| `Google.Cloud.Firestore.V1.FirestoreClient` |   |

### DatabaseId

    public string DatabaseId { get; }

The database ID associated with this database.The value will be "(default)" for the project-default database.

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

### ProjectId

    public string ProjectId { get; }

The project ID associated with this database.

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

## Methods

### Collection(string)

    public CollectionReference Collection(string path)

Creates a local [CollectionReference](https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.Firestore/latest/Google.Cloud.Firestore.CollectionReference) for the given path, which must include
an odd number of slash-separated identifiers. This does not perform any remote operations.

| **Parameter** ||
|---|---|
| **Name** | **Description** |
| `path` | `https://learn.microsoft.com/dotnet/api/system.string` The collection path, e.g. `col1/doc1/col2`. |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.Firestore/latest/Google.Cloud.Firestore.CollectionReference` | A collection reference. |

### CollectionGroup(string)

    public Query CollectionGroup(string collectionId)

Creates and returns a new [Query](https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.Firestore/latest/Google.Cloud.Firestore.Query) that includes all documents in the
database that are contained in a collection or subcollection with the
given collection ID.

| **Parameter** ||
|---|---|
| **Name** | **Description** |
| `collectionId` | `https://learn.microsoft.com/dotnet/api/system.string` Identifies the collections to query over. Every collection or subcollection with this ID as the last segment of its path will be included. Must not contain a slash. |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.Firestore/latest/Google.Cloud.Firestore.Query` | The created [Query](https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.Firestore/latest/Google.Cloud.Firestore.Query). |

### Create(string, FirestoreClient)

    public static FirestoreDb Create(string projectId = null, FirestoreClient client = null)

Creates an instance for the specified project, using the specified Google.Cloud.Firestore.V1.FirestoreClient for RPC operations.

| **Parameters** ||
|---|---|
| **Name** | **Description** |
| `projectId` | `https://learn.microsoft.com/dotnet/api/system.string` The ID of the Google Cloud project that contains the database. May be null, in which case the project will be automatically detected if possible. |
| `client` | `Google.Cloud.Firestore.V1.FirestoreClient` The client to use for RPC operations. May be null, in which case a client will be created with default credentials. |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.Firestore/latest/Google.Cloud.Firestore.FirestoreDb` | A new instance. |

### CreateAsync(string, FirestoreClient)

    public static Task<FirestoreDb> CreateAsync(string projectId = null, FirestoreClient client = null)

Asynchronously creates an instance for the specified project, using the specified Google.Cloud.Firestore.V1.FirestoreClient for RPC operations.

| **Parameters** ||
|---|---|
| **Name** | **Description** |
| `projectId` | `https://learn.microsoft.com/dotnet/api/system.string` The ID of the Google Cloud project that contains the database. May be null, in which case the project will be automatically detected if possible. |
| `client` | `Google.Cloud.Firestore.V1.FirestoreClient` The client to use for RPC operations. May be null, in which case a client will be created with default credentials. |

| **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.FirestoreDb` | A task representing the asynchronous operation. When complete, the result of the task is the new instance. |

### Document(string)

    public DocumentReference Document(string path)

Creates a local [DocumentReference](https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.Firestore/latest/Google.Cloud.Firestore.DocumentReference) for the given path, which must include
an even number of slash-separated identifiers. This does not perform any remote operations.

| **Parameter** ||
|---|---|
| **Name** | **Description** |
| `path` | `https://learn.microsoft.com/dotnet/api/system.string` The document path, e.g. `col1/doc1/col2/doc2`. |

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

### GetAllSnapshotsAsync(IEnumerable\<DocumentReference\>, FieldMask, CancellationToken)

    public Task<IList<DocumentSnapshot>> GetAllSnapshotsAsync(IEnumerable<DocumentReference> documents, FieldMask fieldMask, CancellationToken cancellationToken = default)

Fetches document snapshots from the server, potentially limiting the fields returned.

| **Parameters** ||
|---|---|
| **Name** | **Description** |
| `documents` | `https://learn.microsoft.com/dotnet/api/system.collections.generic.ienumerable-1https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.Firestore/latest/Google.Cloud.Firestore.DocumentReference` The document references to fetch. Must not be null, or contain null references. |
| `fieldMask` | `https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.Firestore/latest/Google.Cloud.Firestore.FieldMask` The field mask to use to restrict which fields are retrieved. May be null, in which case no field mask is applied, and the complete documents are retrieved. |
| `cancellationToken` | `https://learn.microsoft.com/dotnet/api/system.threading.cancellationtoken` A cancellation token for the operation. |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| ``https://learn.microsoft.com/dotnet/api/system.threading.tasks.task-1System.Collections.Generic.IList`1https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.Firestore/latest/Google.Cloud.Firestore.DocumentSnapshot`` | The document snapshots, in the same order as `documents`. |

**Remarks** Any documents which are missing are represented in the returned list by a [DocumentSnapshot](https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.Firestore/latest/Google.Cloud.Firestore.DocumentSnapshot)
with [Exists](https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.Firestore/latest/Google.Cloud.Firestore.DocumentSnapshot#Google_Cloud_Firestore_DocumentSnapshot_Exists) value of `false`.

### GetAllSnapshotsAsync(IEnumerable\<DocumentReference\>, CancellationToken)

    public Task<IList<DocumentSnapshot>> GetAllSnapshotsAsync(IEnumerable<DocumentReference> documents, CancellationToken cancellationToken = default)

Fetches document snapshots from the server.

| **Parameters** ||
|---|---|
| **Name** | **Description** |
| `documents` | `https://learn.microsoft.com/dotnet/api/system.collections.generic.ienumerable-1https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.Firestore/latest/Google.Cloud.Firestore.DocumentReference` The document references to fetch. Must not be null, or contain null references. |
| `cancellationToken` | `https://learn.microsoft.com/dotnet/api/system.threading.cancellationtoken` A cancellation token for the operation. |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| ``https://learn.microsoft.com/dotnet/api/system.threading.tasks.task-1System.Collections.Generic.IList`1https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.Firestore/latest/Google.Cloud.Firestore.DocumentSnapshot`` | The document snapshots, in the same order as `documents`. |

**Remarks** Any documents which are missing are represented in the returned list by a [DocumentSnapshot](https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.Firestore/latest/Google.Cloud.Firestore.DocumentSnapshot)
with [Exists](https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.Firestore/latest/Google.Cloud.Firestore.DocumentSnapshot#Google_Cloud_Firestore_DocumentSnapshot_Exists) value of `false`.

### ListRootCollectionsAsync()

    public IAsyncEnumerable<CollectionReference> ListRootCollectionsAsync()

Asynchronously retrieves the root collection IDs from the server.

| **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.CollectionReference` | All the root collection references, in a lazily-iterated sequence. |

### RunTransactionAsync(Func\<Transaction, Task\>, TransactionOptions, CancellationToken)

    public Task RunTransactionAsync(Func<Transaction, Task> callback, TransactionOptions options = null, CancellationToken cancellationToken = default)

Runs a transaction asynchronously, with an asynchronous callback that doesn't return a value.
The specified callback is executed for a newly-created transaction. If committing the transaction
fails, the whole operation is retried based on [MaxAttempts](https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.Firestore/latest/Google.Cloud.Firestore.TransactionOptions#Google_Cloud_Firestore_TransactionOptions_MaxAttempts).

| **Parameters** ||
|---|---|
| **Name** | **Description** |
| `callback` | `https://learn.microsoft.com/dotnet/api/system.func-2https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.Firestore/latest/Google.Cloud.Firestore.Transactionhttps://learn.microsoft.com/dotnet/api/system.threading.tasks.task` The callback to execute. Must not be null. |
| `options` | `https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.Firestore/latest/Google.Cloud.Firestore.TransactionOptions` The options for the transaction. May be null, in which case default options will be used. |
| `cancellationToken` | `https://learn.microsoft.com/dotnet/api/system.threading.cancellationtoken` A cancellation token for the operation. This is exposed to the callback through [CancellationToken](https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.Firestore/latest/Google.Cloud.Firestore.Transaction#Google_Cloud_Firestore_Transaction_CancellationToken) and applied to all RPCs to begin, rollback or commit the transaction. |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://learn.microsoft.com/dotnet/api/system.threading.tasks.task` | A task which completes when the transaction has committed. |

### RunTransactionAsync\<T\>(Func\<Transaction, Task\<T\>\>, TransactionOptions, CancellationToken)

    public Task<T> RunTransactionAsync<T>(Func<Transaction, Task<T>> callback, TransactionOptions options = null, CancellationToken cancellationToken = default)

Runs a transaction asynchronously, with an asynchronous callback that returns a value.
The specified callback is executed for a newly-created transaction. If committing the transaction
fails, the whole operation is retried based on [MaxAttempts](https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.Firestore/latest/Google.Cloud.Firestore.TransactionOptions#Google_Cloud_Firestore_TransactionOptions_MaxAttempts).

| **Parameters** ||
|---|---|
| **Name** | **Description** |
| `callback` | `https://learn.microsoft.com/dotnet/api/system.func-2https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.Firestore/latest/Google.Cloud.Firestore.Transactionhttps://learn.microsoft.com/dotnet/api/system.threading.tasks.task-1` The callback to execute. Must not be null. |
| `options` | `https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.Firestore/latest/Google.Cloud.Firestore.TransactionOptions` The options for the transaction. May be null, in which case default options will be used. |
| `cancellationToken` | `https://learn.microsoft.com/dotnet/api/system.threading.cancellationtoken` A cancellation token for the operation. This is exposed to the callback through [CancellationToken](https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.Firestore/latest/Google.Cloud.Firestore.Transaction#Google_Cloud_Firestore_Transaction_CancellationToken) and applied to all RPCs to begin, rollback or commit the transaction. |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://learn.microsoft.com/dotnet/api/system.threading.tasks.task-1` | A task which completes when the transaction has committed. The result of the task then contains the result of the callback. |

| **Type Parameter** ||
|---|---|
| **Name** | **Description** |
| `T` | The result type of the callback. |

### StartBatch()

    public WriteBatch StartBatch()

Creates a write batch, which can be used to commit multiple mutations atomically.

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.Firestore/latest/Google.Cloud.Firestore.WriteBatch` | A write batch for this database. |

### WithWarningLogger(Action\<string\>)

    public FirestoreDb WithWarningLogger(Action<string> warningLogger)

Returns a new [FirestoreDb](https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.Firestore/latest/Google.Cloud.Firestore.FirestoreDb) with the same project, database and client as this one,
but the given writer for warning logs.

| **Parameter** ||
|---|---|
| **Name** | **Description** |
| `warningLogger` | `https://learn.microsoft.com/dotnet/api/system.action-1https://learn.microsoft.com/dotnet/api/system.string` The logger for warnings. May be null. |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.Firestore/latest/Google.Cloud.Firestore.FirestoreDb` | A new [FirestoreDb](https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.Firestore/latest/Google.Cloud.Firestore.FirestoreDb) based on this one, with the given warning logger. |