WriteBatch | Doclava
public class

WriteBatch

extends Object
java.lang.Object
   ↳ com.google.firebase.firestore.WriteBatch

Class Overview

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

Public Methods
Task<Void> commit()
Commits all of the writes in this write batch as a single atomic unit.
WriteBatch delete(DocumentReference documentRef)
Deletes the document referred to by the provided DocumentReference.
WriteBatch set(DocumentReference documentRef, Map<String, Object> data)
Overwrites the document referred to by the provided DocumentReference.
WriteBatch set(DocumentReference documentRef, Map<String, Object> data, SetOptions options)
Writes to the document referred to by the provided DocumentReference.
WriteBatch set(DocumentReference documentRef, Object pojo)
Overwrites the document referred to by the provided DocumentReference.
WriteBatch set(DocumentReference documentRef, Object pojo, SetOptions options)
Writes to the document referred to by the provided DocumentReference.
WriteBatch update(DocumentReference documentRef, Map<String, Object> data)
Updates fields in the document referred to by the provided DocumentReference.
WriteBatch update(DocumentReference documentRef, String field, Object value, Object... moreFieldsAndValues)
Updates field in the document referred to by the provided DocumentReference.
WriteBatch update(DocumentReference documentRef, FieldPath fieldPath, Object value, Object... moreFieldsAndValues)
Updates fields in the document referred to by the provided DocumentReference.
[Expand]
Inherited Methods
From class java.lang.Object

Public Methods

public Task<Void> commit ()

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

Returns
Task<Void> A Task that will be resolved when the write finishes.

public WriteBatch delete (DocumentReference documentRef)

Deletes the document referred to by the provided DocumentReference.

Parameters
documentRef DocumentReference:The DocumentReference to delete.

Returns
WriteBatch This WriteBatch instance. Used for chaining method calls.

public WriteBatch set (DocumentReference documentRef, Map<String, Object> data)

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 DocumentReference to overwrite.

data Map:A map of the fields and values for the document.

Returns
WriteBatch This WriteBatch instance. Used for chaining method calls.

public WriteBatch set (DocumentReference documentRef, Map<String, Object> data, SetOptions options)

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 DocumentReference to overwrite.

data Map:A map of the fields and values for the document.

options SetOptions:An object to configure the set behavior.

Returns
WriteBatch This WriteBatch instance. Used for chaining method calls.

public WriteBatch set (DocumentReference documentRef, Object pojo)

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 DocumentReference to overwrite.

pojo Object:The POJO that will be used to populate the document contents.

Returns
WriteBatch This WriteBatch instance. Used for chaining method calls.

public WriteBatch set (DocumentReference documentRef, Object pojo, SetOptions options)

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 DocumentReference to overwrite.

pojo Object:The POJO that will be used to populate the document contents.

options SetOptions:An object to configure the set behavior.

Returns
WriteBatch This WriteBatch instance. Used for chaining method calls.

public WriteBatch update (DocumentReference documentRef, Map<String, Object> data)

Updates fields in the document referred to by the provided DocumentReference. If no document exists yet, the update will fail.

Parameters
documentRef DocumentReference:The DocumentReference to update.

data Map:A map of field / value pairs to update. Fields can contain dots to reference nested fields within the document.

Returns
WriteBatch This WriteBatch instance. Used for chaining method calls.

public WriteBatch update (DocumentReference documentRef, String field, Object value, Object... moreFieldsAndValues)

Updates field in the document referred to by the provided DocumentReference. If no document exists yet, the update will fail.

Parameters
documentRef DocumentReference:The DocumentReference to update.

field String:The first field to update. Fields can contain dots to reference a nested field within the document.

value Object:The first value

moreFieldsAndValues Object:Additional field/value pairs.

Returns
WriteBatch This WriteBatch instance. Used for chaining method calls.

public WriteBatch update (DocumentReference documentRef, FieldPath fieldPath, Object value, Object... moreFieldsAndValues)

Updates fields in the document referred to by the provided DocumentReference. If no document exists yet, the update will fail.

Parameters
documentRef DocumentReference:The DocumentReference to update.

fieldPath FieldPath:The first field to update.

value Object:The first value

moreFieldsAndValues Object:Additional field/value pairs.

Returns
WriteBatch This WriteBatch instance. Used for chaining method calls.