Firebase.Firestore.WriteBatch

A batch of write operations, used to perform multiple writes as a single atomic unit.

Summary

AWriteBatch object can be acquired by callingFirebaseFirestore.StartBatch. It provides methods for adding writes to the write batch. None of the writes will be committed (or visible locally) untilCommitAsync is called.

Unlike transactions, write batches are persisted offline and therefore are preferable when you don't need to condition your writes on read data.

Public functions

CommitAsync()
Task
Commits all of the writes in this write batch as a single atomic unit.
Delete(DocumentReference documentReference)
Deletes the document referenced by the providedDocumentReference.
Set(DocumentReference documentReference, object documentData,SetOptions options)
Writes to the document referred to by the providedDocumentReference.
Update(DocumentReference documentReference, IDictionary< string, object > updates)
Updates fields in the document referred to by the providedDocumentReference.
Update(DocumentReference documentReference, string field, object value)
Updates the field in the document referred to by the providedDocumentReference.
Update(DocumentReference documentReference, IDictionary<FieldPath, object > updates)
Updates fields in the document referred to by the providedDocumentReference.

Public functions

CommitAsync

TaskCommitAsync()

Commits all of the writes in this write batch as a single atomic unit.

Details
Returns
The write result of the server operation. The task will not complete while the client is offline, though local changes will be visible immediately.

Delete

WriteBatchDelete(DocumentReferencedocumentReference)

Deletes the document referenced by the providedDocumentReference.

Details
Parameters
documentReference
The document to delete. Must not benull.
Returns
This batch, for the purposes of method chaining.

Set

WriteBatchSet(DocumentReferencedocumentReference,objectdocumentData,SetOptionsoptions)

Writes to the document referred to by the providedDocumentReference.

If the document does not yet exist, it will be created. If you passoptions , the provided data can be merged into an existing document.

Details
Parameters
documentReference
The document in which to set the data. Must not benull.
documentData
The data for the document. Must not benull.
options
The options to use when updating the document. May benull, which is equivalent toSetOptions.Overwrite.
Returns
This batch, for the purposes of method chaining.

Update

WriteBatchUpdate(DocumentReferencedocumentReference,IDictionary<string,object>updates)

Updates fields in the document referred to by the providedDocumentReference.

If no document exists yet, the update will fail.

Details
Parameters
documentReference
The document to update. Must not benull.
updates
A dictionary of field / value pairs to update. Fields can contain dots to reference nested fields in the document. Fields not present in this dictionary are not updated. Must not benull.
Returns
This batch, for the purposes of method chaining.

Update

WriteBatchUpdate(DocumentReferencedocumentReference,stringfield,objectvalue)

Updates the field in the document referred to by the providedDocumentReference.

If no document exists yet, the update will fail.

Details
Parameters
documentReference
The document to update. Must not benull.
field
The dot-separated name of the field to update. Must not benull.
value
The new value for the field. May benull.
Returns
This batch, for the purposes of method chaining.

Update

WriteBatchUpdate(DocumentReferencedocumentReference,IDictionary<FieldPath,object>updates)

Updates fields in the document referred to by the providedDocumentReference.

If no document exists yet, the update will fail.

Details
Parameters
documentReference
The document to update. Must not benull.
updates
A dictionary of field / value pairs to update. Fields not present in this dictionary are not updated. Must not benull.
Returns
This batch, for the purposes of method chaining.

Except as otherwise noted, the content of this page is licensed under theCreative Commons Attribution 4.0 License, and code samples are licensed under theApache 2.0 License. For details, see theGoogle Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.

Last updated 2022-07-27 UTC.