WriteBatch
class WriteBatch
A write batch, used to perform multiple writes as a single atomic unit.
A Batch object can be acquired by calling batch. It provides methods for adding writes to the write batch. None of the writes will be committed (or visible locally) until 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.
Subclassing Note: Cloud Firestore classes are not meant to be subclassed except for use in test mocks. Subclassing is not supported in production code and new SDK releases may break code that does so.
Summary
Nested types |
|---|
interface WriteBatch.FunctionAn interface for providing code to be executed within a |
Public functions |
|
|---|---|
Task<Void!> |
commit()Commits all of the writes in this write batch as a single atomic unit. |
WriteBatch |
delete(documentRef: DocumentReference)Deletes the document referred to by the provided |
WriteBatch |
set(documentRef: DocumentReference, data: Any)Overwrites the document referred to by the provided |
WriteBatch |
set(documentRef: DocumentReference, data: Any, options: SetOptions)Writes to the document referred to by the provided |
WriteBatch |
Updates fields in the document referred to by the provided |
WriteBatch |
update(Updates field in the document referred to by the provided |
WriteBatch |
update(Updates fields in the document referred to by the provided |
Public functions
commit
fun commit(): Task<Void!>
Commits all of the writes in this write batch as a single atomic unit.
delete
fun delete(documentRef: DocumentReference): WriteBatch
Deletes the document referred to by the provided DocumentReference.
| Parameters | |
|---|---|
documentRef: DocumentReference |
The |
| Returns | |
|---|---|
WriteBatch |
This |
set
fun set(documentRef: DocumentReference, data: Any): WriteBatch
Overwrites the document referred to by the provided DocumentReference. If the document does not yet exist, it will be created. If a document already exists, it will be overwritten.
| Parameters | |
|---|---|
documentRef: DocumentReference |
The |
data: Any |
The data to write to the document (like a Map or a POJO containing the desired document contents). |
| Returns | |
|---|---|
WriteBatch |
This |
set
fun set(documentRef: DocumentReference, data: Any, options: SetOptions): WriteBatch
Writes to the document referred to by the provided DocumentReference. If the document does not yet exist, it will be created. If you pass SetOptions, the provided data can be merged into an existing document.
| Parameters | |
|---|---|
documentRef: DocumentReference |
The |
data: Any |
The data to write to the document (like a Map or a POJO containing the desired document contents). |
options: SetOptions |
An object to configure the set behavior. |
| Returns | |
|---|---|
WriteBatch |
This |
update
fun update(documentRef: DocumentReference, data: (Mutable)Map<String!, Any!>): WriteBatch
Updates fields in the document referred to by the provided DocumentReference. If no document exists yet, the update will fail.
| Parameters | |
|---|---|
documentRef: DocumentReference |
The |
data: (Mutable)Map<String!, Any!> |
A map of field / value pairs to update. Fields can contain dots to reference nested fields within the document. |
| Returns | |
|---|---|
WriteBatch |
This |
update
fun update(
documentRef: DocumentReference,
field: String,
value: Any?,
moreFieldsAndValues: Array<Any!>!
): WriteBatch
Updates field in the document referred to by the provided DocumentReference. If no document exists yet, the update will fail.
| Parameters | |
|---|---|
documentRef: DocumentReference |
The |
field: String |
The first field to update. Fields can contain dots to reference a nested field within the document. |
value: Any? |
The first value |
moreFieldsAndValues: Array<Any!>! |
Additional field/value pairs. |
| Returns | |
|---|---|
WriteBatch |
This |
update
fun update(
documentRef: DocumentReference,
fieldPath: FieldPath,
value: Any?,
moreFieldsAndValues: Array<Any!>!
): WriteBatch
Updates fields in the document referred to by the provided DocumentReference. If no document exists yet, the update will fail.
| Parameters | |
|---|---|
documentRef: DocumentReference |
The |
fieldPath: FieldPath |
The first field to update. |
value: Any? |
The first value |
moreFieldsAndValues: Array<Any!>! |
Additional field/value pairs. |
| Returns | |
|---|---|
WriteBatch |
This |