[ Web Proxy ]
URL:
Viewing: https://firebase.google.com/docs/reference/cpp/class/firebase/firestore/transaction [Back]  [Original]

firebase::firestore::Transaction Class Reference  |  Firebase Skip to main content
Overview Fundamentals AI Build Run Reference Samples
Firebase [Firebase]
Send feedback Stay organized with collections Save and categorize content based on your preferences.

firebase::firestore::Transaction

#include <transaction.h>

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

Summary

You cannot create a Transaction directly; use Firestore::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(const Transaction & other)
Deleted copy constructor.
~Transaction()
Destructor.

Public functions

Delete(const DocumentReference & document)
virtual void
Deletes the document referred to by the provided reference.
Get(const DocumentReference & document, Error *error_code, std::string *error_message)
Reads the document referred by the provided reference.
Set(const DocumentReference & document, const MapFieldValue & data, const SetOptions & options)
virtual void
Writes to the document referred to by the provided reference.
Update(const DocumentReference & document, const MapFieldValue & data)
virtual void
Updates fields in the document referred to by the provided reference.
Update(const DocumentReference & document, const MapFieldPathValue & data)
virtual void
Updates fields in the document referred to by the provided reference.
operator=(const Transaction & other)=delete
Deleted copy assignment operator.

Protected functions

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

Public functions

Delete

virtual void Delete(
  const DocumentReference & document
)

Deletes the document referred to by the provided reference.

Details
Parameters
document
The DocumentReference to delete.

Get

virtual DocumentSnapshot Get(
  const DocumentReference & document,
  Error *error_code,
  std::string *error_message
)

Reads the document referred by the provided reference.

Details
Parameters
document
The DocumentReference 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 this DocumentReference or invalid DocumentSnapshot if there is any error.

Set

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

Transaction

 Transaction(
  const Transaction & other
)=delete

Deleted copy constructor.

A Transaction object is only valid for the duration of the callback you pass to Firestore::RunTransaction() and cannot be copied.

Update

virtual void 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.

Update

virtual void 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.

operator=

Transaction & operator=(
  const Transaction & other
)=delete

Deleted copy assignment operator.

A Transaction object is only valid for the duration of the callback you pass to Firestore::RunTransaction() and cannot be copied.

~Transaction

virtual  ~Transaction()

Destructor.

Protected functions

Transaction

 Transaction()=default

Default constructor, to be used only for mocking a Transaction.

Send feedback

Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License, and code samples are licensed under the Apache 2.0 License. For details, see the Google Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.

Last updated 2024-01-23 UTC.

Need to tell us more? [[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Missing the information I need","missingTheInformationINeed","thumb-down"],["Too complicated / too many steps","tooComplicatedTooManySteps","thumb-down"],["Out of date","outOfDate","thumb-down"],["Samples / code issue","samplesCodeIssue","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2024-01-23 UTC."],[],[]]

Web Proxy Viewer  |  New URL  |  Original Page