WriteBatch
A write batch, used to perform multiple writes as a single atomic unit.
A WriteBatch object can be acquired by calling firestore.batch()
. It provides methods for adding
writes to the write batch. None of the writes will be committed (or visible locally) until
WriteBatch.commit()
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.
Methods
commit
</>Commits all of the writes in this write batch as a single atomic unit.
commit(): Promise<void>;
delete
</>Deletes the document referred to by the provided DocumentReference
.
delete(documentRef: DocumentReference): WriteBatch;
set
</>Writes to the document referred to by the provided DocumentReference. If the document does not exist yet, it will be created. If you pass SetOptions, the provided data can be merged into the existing document.
set(documentRef: DocumentReference<>, data: , options?: SetOptions): WriteBatch;
update
</>Signature 1
</>Updates fields in the document referred to by the provided DocumentReference. The update will fail if applied to a document that does not exist.
update(documentRef: DocumentReference<>, data: Partial<>): WriteBatch;
Signature 2
</>Updates fields in the document referred to by this DocumentReference. The update will fail if applied to a document that does not exist.
update(documentRef: DocumentReference<>, field: | FieldPath, value: | FieldValue, moreFieldAndValues: any[]): WriteBatch;