firebase::firestore::WriteBatch

#include <write_batch.h>

A write batch is used to perform multiple writes as a single atomic unit.

Summary

AWriteBatch object provides methods for adding writes to the write batch. None of the writes will be committed (or visible locally) untilCommit() 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.

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.

Constructors and Destructors

WriteBatch()
Creates an invalidWriteBatch that has to be reassigned before it can be used.
WriteBatch(constWriteBatch & other)
Copy constructor.
WriteBatch(WriteBatch && other)
Move constructor.
~WriteBatch()

Public functions

Commit()
virtualFuture< void >
Commits all of the writes in this write batch as a single atomic unit.
Delete(constDocumentReference & document)
virtualWriteBatch &
Deletes the document referred to by the provided reference.
Set(constDocumentReference & document, constMapFieldValue & data, constSetOptions & options)
virtualWriteBatch &
Writes to the document referred to by the provided reference.
Update(constDocumentReference & document, constMapFieldValue & data)
virtualWriteBatch &
Updates fields in the document referred to by the provided reference.
Update(constDocumentReference & document, constMapFieldPathValue & data)
virtualWriteBatch &
Updates fields in the document referred to by the provided reference.
is_valid() const
bool
Returns true if thisWriteBatch is valid, false if it is not valid.
operator=(constWriteBatch & other)
Copy assignment operator.
operator=(WriteBatch && other)
Move assignment operator.

Public functions

Commit

virtualFuture<void>Commit()

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

Details
Returns
AFuture that will be resolved when the write finishes.

Delete

virtualWriteBatch&Delete(constDocumentReference&document)

Deletes the document referred to by the provided reference.

Details
Parameters
document
TheDocumentReference to delete.
Returns
ThisWriteBatch instance. Used for chaining method calls.

Set

virtualWriteBatch&Set(constDocumentReference&document,constMapFieldValue&data,constSetOptions&options)

Writes to the document referred to by the provided reference.

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

Details
Parameters
document
TheDocumentReference to write to.
data
A map of the fields and values to write to the document.
options
An object to configure theSet() behavior (optional).
Returns
ThisWriteBatch instance. Used for chaining method calls.

Update

virtualWriteBatch&Update(constDocumentReference&document,constMapFieldValue&data)

Updates fields in the document referred to by the provided reference.

If no document exists yet, the update will fail.

Details
Parameters
document
TheDocumentReference to update.
data
A map of field / value pairs to update. Fields can contain dots to reference nested fields within the document.
Returns
ThisWriteBatch instance. Used for chaining method calls.

Update

virtualWriteBatch&Update(constDocumentReference&document,constMapFieldPathValue&data)

Updates fields in the document referred to by the provided reference.

If no document exists yet, the update will fail.

Details
Parameters
document
TheDocumentReference to update.
data
A map fromFieldPath toFieldValue to update.
Returns
ThisWriteBatch instance. Used for chaining method calls.

WriteBatch

WriteBatch()

Creates an invalidWriteBatch that has to be reassigned before it can be used.

Calling any member function on an invalidWriteBatch will be a no-op. If the function returns a value, it will return a zero, empty, or invalid value, depending on the type of the value.

WriteBatch

WriteBatch(constWriteBatch&other)

Copy constructor.

This performs a deep copy, creating an independent instance.

Details
Parameters
other
WriteBatch to copy from.

WriteBatch

WriteBatch(WriteBatch&&other)

Move constructor.

Moving is more efficient than copying for aWriteBatch. After being moved from, aWriteBatch is equivalent to its default-constructed state.

Details
Parameters
other
WriteBatch to move data from.

is_valid

boolis_valid()const

Returns true if thisWriteBatch is valid, false if it is not valid.

An invalidWriteBatch could be the result of:

Details
Returns
true if thisWriteBatch is valid, false if thisWriteBatch is invalid.

operator=

WriteBatch&operator=(constWriteBatch&other)

Copy assignment operator.

This performs a deep copy, creating an independent instance.

Details
Parameters
other
WriteBatch to copy from.
Returns
Reference to the destinationWriteBatch.

operator=

WriteBatch&operator=(WriteBatch&&other)

Move assignment operator.

Moving is more efficient than copying for aWriteBatch. After being moved from, aWriteBatch is equivalent to its default-constructed state.

Details
Parameters
other
WriteBatch to move data from.
Returns
Reference to the destinationWriteBatch.

~WriteBatch

virtual~WriteBatch()

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 2024-01-23 UTC.