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 WriteBatch

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

A batch of write operations, to be applied in a single commit.

## Inheritance

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

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

## Methods

### CommitAsync(CancellationToken)

    public Task<IList<WriteResult>> CommitAsync(CancellationToken cancellationToken = default)

Commits the batch on the server.

| **Parameter** ||
|---|---|
| **Name** | **Description** |
| `cancellationToken` | `https://learn.microsoft.com/dotnet/api/system.threading.cancellationtoken` |

| **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.WriteResult`` | The write results from the commit. |

### Create(DocumentReference, object)

    public WriteBatch Create(DocumentReference documentReference, object documentData)

Adds a write operation which will create the specified document with a precondition
that it doesn't exist already.

| **Parameters** ||
|---|---|
| **Name** | **Description** |
| `documentReference` | `https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.Firestore/latest/Google.Cloud.Firestore.DocumentReference` A document reference indicating the path of the document to create. Must not be null. |
| `documentData` | `https://learn.microsoft.com/dotnet/api/system.object` The data for the document. Must not be null. |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.Firestore/latest/Google.Cloud.Firestore.WriteBatch` | This batch, for the purpose of method chaining |

### Delete(DocumentReference, Precondition)

    public WriteBatch Delete(DocumentReference documentReference, Precondition precondition = null)

Adds a write operation that deletes the specified document, with an optional precondition.

| **Parameters** ||
|---|---|
| **Name** | **Description** |
| `documentReference` | `https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.Firestore/latest/Google.Cloud.Firestore.DocumentReference` A document reference indicating the path of the document to delete. Must not be null. |
| `precondition` | `https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.Firestore/latest/Google.Cloud.Firestore.Precondition` Optional precondition for deletion. May be null, in which case the deletion is unconditional. |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.Firestore/latest/Google.Cloud.Firestore.WriteBatch` | This batch, for the purposes of method chaining. |

### Set(DocumentReference, object, SetOptions)

    public WriteBatch Set(DocumentReference documentReference, object documentData, SetOptions options = null)

Adds an operation that sets data in a document, either replacing it completely or merging fields.

| **Parameters** ||
|---|---|
| **Name** | **Description** |
| `documentReference` | `https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.Firestore/latest/Google.Cloud.Firestore.DocumentReference` A document reference indicating the path of the document to update. Must not be null. |
| `documentData` | `https://learn.microsoft.com/dotnet/api/system.object` The data to store in the document. Must not be null. |
| `options` | `https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.Firestore/latest/Google.Cloud.Firestore.SetOptions` The options to use when setting data in the document. May be null, which is equivalent to [Overwrite](https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.Firestore/latest/Google.Cloud.Firestore.SetOptions#Google_Cloud_Firestore_SetOptions_Overwrite). |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.Firestore/latest/Google.Cloud.Firestore.WriteBatch` | This batch, for the purposes of method chaining. |

### Update(DocumentReference, IDictionary\<FieldPath, object\>, Precondition)

    public WriteBatch Update(DocumentReference documentReference, IDictionary<FieldPath, object> updates, Precondition precondition = null)

Adds an update operation that updates just the specified fields paths in the document, with the corresponding values.

| **Parameters** ||
|---|---|
| **Name** | **Description** |
| `documentReference` | `https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.Firestore/latest/Google.Cloud.Firestore.DocumentReference` A document reference indicating the path of the document to update. Must not be null. |
| `updates` | `https://learn.microsoft.com/dotnet/api/system.collections.generic.idictionary-2https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.Firestore/latest/Google.Cloud.Firestore.FieldPathhttps://learn.microsoft.com/dotnet/api/system.object` The updates to perform on the document, keyed by the field path to update. Fields not present in this dictionary are not updated. Must not be null or empty. |
| `precondition` | `https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.Firestore/latest/Google.Cloud.Firestore.Precondition` Optional precondition for updating the document. May be null, which is equivalent to [MustExist](https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.Firestore/latest/Google.Cloud.Firestore.Precondition#Google_Cloud_Firestore_Precondition_MustExist). |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.Firestore/latest/Google.Cloud.Firestore.WriteBatch` | This batch, for the purposes of method chaining. |

### Update(DocumentReference, IDictionary\<string, object\>, Precondition)

    public WriteBatch Update(DocumentReference documentReference, IDictionary<string, object> updates, Precondition precondition = null)

Adds an update operation that updates just the specified fields paths in the document, with the corresponding values.

| **Parameters** ||
|---|---|
| **Name** | **Description** |
| `documentReference` | `https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.Firestore/latest/Google.Cloud.Firestore.DocumentReference` A document reference indicating the path of the document to update. Must not be null. |
| `updates` | `https://learn.microsoft.com/dotnet/api/system.collections.generic.idictionary-2https://learn.microsoft.com/dotnet/api/system.stringhttps://learn.microsoft.com/dotnet/api/system.object` The updates to perform on the document, keyed by the dot-separated field path to update. Fields not present in this dictionary are not updated. Must not be null or empty. |
| `precondition` | `https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.Firestore/latest/Google.Cloud.Firestore.Precondition` Optional precondition for updating the document. May be null, which is equivalent to [MustExist](https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.Firestore/latest/Google.Cloud.Firestore.Precondition#Google_Cloud_Firestore_Precondition_MustExist). |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.Firestore/latest/Google.Cloud.Firestore.WriteBatch` | This batch, for the purposes of method chaining. |

### Update(DocumentReference, string, object, Precondition)

    public WriteBatch Update(DocumentReference documentReference, string field, object value, Precondition precondition = null)

Adds an update operation that updates just the specified field in the document, with the corresponding values.

| **Parameters** ||
|---|---|
| **Name** | **Description** |
| `documentReference` | `https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.Firestore/latest/Google.Cloud.Firestore.DocumentReference` A document reference indicating the path of the document to update. Must not be null. |
| `field` | `https://learn.microsoft.com/dotnet/api/system.string` The dot-separated name of the field to update. Must not be null. |
| `value` | `https://learn.microsoft.com/dotnet/api/system.object` The new value for the field. May be null. |
| `precondition` | `https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.Firestore/latest/Google.Cloud.Firestore.Precondition` Optional precondition for updating the document. May be null, which is equivalent to [MustExist](https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.Firestore/latest/Google.Cloud.Firestore.Precondition#Google_Cloud_Firestore_Precondition_MustExist). |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.Firestore/latest/Google.Cloud.Firestore.WriteBatch` | This batch, for the purposes of method chaining. |