firebase::firestore::WriteBatch

#include <write_batch.h>

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

Summary

A WriteBatch object 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.

Constructors and Destructors

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

Public functions

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

Public functions

Commit

virtual Future< void > Commit()

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

Details
Returns
A Future that will be resolved when the write finishes.

Delete

virtual WriteBatch & Delete(
  const DocumentReference & document
)

Deletes the document referred to by the provided reference.

Details
Parameters
document
The DocumentReference to delete.
Returns
This WriteBatch instance. Used for chaining method calls.

Set

virtual WriteBatch & Set(
  const DocumentReference & document,
  const MapFieldValue & data,
  const SetOptions & options
)

Writes to the document referred to by the provided reference.

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.

Details
Parameters
document
The DocumentReference to write to.
data
A map of the fields and values to write to the document.
options
An object to configure the Set() behavior (optional).
Returns
This WriteBatch instance. Used for chaining method calls.

Update

virtual WriteBatch & Update(
  const DocumentReference & document,
  const MapFieldValue & data
)

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

If no document exists yet, the update will fail.

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

Update

virtual WriteBatch & Update(
  const DocumentReference & document,
  const MapFieldPathValue & data
)

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

If no document exists yet, the update will fail.

Details
Parameters
document
The DocumentReference to update.
data
A map from FieldPath to FieldValue to update.
Returns
This WriteBatch instance. Used for chaining method calls.

WriteBatch

 WriteBatch()

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

Calling any member function on an invalid WriteBatch 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(
  const WriteBatch & 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 a WriteBatch. After being moved from, a WriteBatch is equivalent to its default-constructed state.

Details
Parameters
other
WriteBatch to move data from.

is_valid

bool is_valid() const 

Returns true if this WriteBatch is valid, false if it is not valid.

An invalid WriteBatch could be the result of:

Details
Returns
true if this WriteBatch is valid, false if this WriteBatch is invalid.

operator=

WriteBatch & operator=(
  const WriteBatch & other
)

Copy assignment operator.

This performs a deep copy, creating an independent instance.

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

operator=

WriteBatch & operator=(
  WriteBatch && other
)

Move assignment operator.

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

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

~WriteBatch

virtual  ~WriteBatch()