Class WriteBatch
A batch of write operations, to be applied in a single commit.
Namespace: Google.Cloud.Firestore
Assembly: Google.Cloud.Firestore.dll
Syntax
public sealed class WriteBatch
Methods
CommitAsync(CancellationToken)
Commits the batch on the server.
Declaration
public Task<IList<WriteResult>> CommitAsync(CancellationToken cancellationToken = default)
Parameters
Type | Name | Description |
---|---|---|
CancellationToken | cancellationToken |
Returns
Type | Description |
---|---|
Task<IList<WriteResult>> | The write results from the commit. |
Create(DocumentReference, object)
Adds a write operation which will create the specified document with a precondition that it doesn't exist already.
Declaration
public WriteBatch Create(DocumentReference documentReference, object documentData)
Parameters
Type | Name | Description |
---|---|---|
DocumentReference | documentReference | A document reference indicating the path of the document to create. Must not be null. |
object | documentData | The data for the document. Must not be null. |
Returns
Type | Description |
---|---|
WriteBatch | This batch, for the purpose of method chaining |
Delete(DocumentReference, Precondition)
Adds a write operation that deletes the specified document, with an optional precondition.
Declaration
public WriteBatch Delete(DocumentReference documentReference, Precondition precondition = null)
Parameters
Type | Name | Description |
---|---|---|
DocumentReference | documentReference | A document reference indicating the path of the document to delete. Must not be null. |
Precondition | precondition | Optional precondition for deletion. May be null, in which case the deletion is unconditional. |
Returns
Type | Description |
---|---|
WriteBatch | This batch, for the purposes of method chaining. |
Set(DocumentReference, object, SetOptions)
Adds an operation that sets data in a document, either replacing it completely or merging fields.
Declaration
public WriteBatch Set(DocumentReference documentReference, object documentData, SetOptions options = null)
Parameters
Type | Name | Description |
---|---|---|
DocumentReference | documentReference | A document reference indicating the path of the document to update. Must not be null. |
object | documentData | The data to store in the document. Must not be null. |
SetOptions | options | The options to use when setting data in the document. May be null, which is equivalent to Overwrite. |
Returns
Type | Description |
---|---|
WriteBatch | This batch, for the purposes of method chaining. |
Update(DocumentReference, IDictionary<FieldPath, object>, Precondition)
Adds an update operation that updates just the specified fields paths in the document, with the corresponding values.
Declaration
public WriteBatch Update(DocumentReference documentReference, IDictionary<FieldPath, object> updates, Precondition precondition = null)
Parameters
Type | Name | Description |
---|---|---|
DocumentReference | documentReference | A document reference indicating the path of the document to update. Must not be null. |
IDictionary<FieldPath, object> | updates | 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 | precondition | Optional precondition for updating the document. May be null, which is equivalent to MustExist. |
Returns
Type | Description |
---|---|
WriteBatch | This batch, for the purposes of method chaining. |
Update(DocumentReference, IDictionary<string, object>, Precondition)
Adds an update operation that updates just the specified fields paths in the document, with the corresponding values.
Declaration
public WriteBatch Update(DocumentReference documentReference, IDictionary<string, object> updates, Precondition precondition = null)
Parameters
Type | Name | Description |
---|---|---|
DocumentReference | documentReference | A document reference indicating the path of the document to update. Must not be null. |
IDictionary<string, object> | updates | 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 | precondition | Optional precondition for updating the document. May be null, which is equivalent to MustExist. |
Returns
Type | Description |
---|---|
WriteBatch | This batch, for the purposes of method chaining. |
Update(DocumentReference, string, object, Precondition)
Adds an update operation that updates just the specified field in the document, with the corresponding values.
Declaration
public WriteBatch Update(DocumentReference documentReference, string field, object value, Precondition precondition = null)
Parameters
Type | Name | Description |
---|---|---|
DocumentReference | documentReference | A document reference indicating the path of the document to update. Must not be null. |
string | field | The dot-separated name of the field to update. Must not be null. |
object | value | The new value for the field. May be null. |
Precondition | precondition | Optional precondition for updating the document. May be null, which is equivalent to MustExist. |
Returns
Type | Description |
---|---|
WriteBatch | This batch, for the purposes of method chaining. |