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 | boolReturns true if this WriteBatch 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 |
| ||
| 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 |
| ||||||
| 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 |
| ||||
| 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 |
| ||||
| 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 |
|
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 |
|
is_valid
boolis_valid()const
Returns true if thisWriteBatch is valid, false if it is not valid.
An invalidWriteBatch could be the result of:
- Creating a
WriteBatchusing the default constructor. - Moving from the
WriteBatch. - Deleting yourFirestore instance, which will invalidate all the
WriteBatchinstances associated with it.
| Details | |
|---|---|
| Returns | true if this WriteBatch 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 |
| ||
| Returns | Reference to the destination WriteBatch. |
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 |
| ||
| Returns | Reference to the destination WriteBatch. |
~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.