firebase::firestore::Transaction

#include <transaction.h>

Transaction provides methods to read and write data within a transaction.

Summary

You cannot create aTransaction directly; useFirestore::RunTransaction() function instead.

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

Transaction(constTransaction & other)
Deleted copy constructor.
~Transaction()
Destructor.

Public functions

Delete(constDocumentReference & document)
virtual void
Deletes the document referred to by the provided reference.
Get(constDocumentReference & document,Error *error_code, std::string *error_message)
Reads the document referred by the provided reference.
Set(constDocumentReference & document, constMapFieldValue & data, constSetOptions & options)
virtual void
Writes to the document referred to by the provided reference.
Update(constDocumentReference & document, constMapFieldValue & data)
virtual void
Updates fields in the document referred to by the provided reference.
Update(constDocumentReference & document, constMapFieldPathValue & data)
virtual void
Updates fields in the document referred to by the provided reference.
operator=(constTransaction & other)=delete
Deleted copy assignment operator.

Protected functions

Transaction()=default
Default constructor, to be used only for mocking aTransaction.

Public functions

Delete

virtualvoidDelete(constDocumentReference&document)

Deletes the document referred to by the provided reference.

Details
Parameters
document
TheDocumentReference to delete.

Get

virtualDocumentSnapshotGet(constDocumentReference&document,Error*error_code,std::string*error_message)

Reads the document referred by the provided reference.

Details
Parameters
document
TheDocumentReference to read.
error_code
An out parameter to capture an error, if one occurred.
error_message
An out parameter to capture error message, if any.
Returns
The contents of the document at thisDocumentReference or invalidDocumentSnapshot if there is any error.

Set

virtualvoidSet(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 overwrite.
data
A map of the fields and values to write to the document.
options
An object to configure theSet() behavior (optional).

Transaction

Transaction(constTransaction&other)=delete

Deleted copy constructor.

ATransaction object is only valid for the duration of the callback you pass toFirestore::RunTransaction() and cannot be copied.

Update

virtualvoidUpdate(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.

Update

virtualvoidUpdate(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.

operator=

Transaction&operator=(constTransaction&other)=delete

Deleted copy assignment operator.

ATransaction object is only valid for the duration of the callback you pass toFirestore::RunTransaction() and cannot be copied.

~Transaction

virtual~Transaction()

Destructor.

Protected functions

Transaction

Transaction()=default

Default constructor, to be used only for mocking aTransaction.

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.