A Transaction
is passed to a Function to provide the methods to read and
write data within the transaction context.
Subclassing Note: Cloud 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.
See Also
Nested Class Summary
interface | Transaction.Function<TResult> | An interface for providing code to be executed within a transaction context. |
Public Method Summary
Transaction |
delete(DocumentReference
documentRef)
Deletes the document referred to by the provided
DocumentReference .
|
DocumentSnapshot | |
Transaction |
set(DocumentReference
documentRef, Object data)
Overwrites the document referred to by the provided
DocumentReference .
|
Transaction |
set(DocumentReference
documentRef, Object data,
SetOptions
options)
Writes to the document referred to by the provided DocumentReference.
|
Transaction |
update(DocumentReference
documentRef, Map<String, Object>
data)
Updates fields in the document referred to by the provided
DocumentReference .
|
Transaction |
update(DocumentReference
documentRef, String field,
Object
value, Object...
moreFieldsAndValues)
Updates fields in the document referred to by the provided
DocumentReference .
|
Transaction |
update(DocumentReference
documentRef, FieldPath
fieldPath, Object value,
Object...
moreFieldsAndValues)
Updates fields in the document referred to by the provided
DocumentReference .
|
Inherited Method Summary
Public Methods
public Transaction delete (DocumentReference documentRef)
Deletes the document referred to by the provided DocumentReference
.
Parameters
documentRef | The DocumentReference to delete. |
---|
Returns
- This
Transaction
instance. Used for chaining method calls.
public DocumentSnapshot get (DocumentReference documentRef)
Reads the document referenced by this DocumentReference
Parameters
documentRef | The DocumentReference to read. |
---|
Returns
- The contents of the Document at this
DocumentReference
.
Throws
FirebaseFirestoreException |
---|
public Transaction set (DocumentReference documentRef, Object data)
Overwrites the document referred to by the provided DocumentReference
.
If the document does not yet exist, it will be created. If a document already exists,
it will be overwritten.
Parameters
documentRef | The DocumentReference to overwrite. |
---|---|
data | The data to write to the document (e.g. a Map or a POJO containing the desired document contents). |
Returns
- This
Transaction
instance. Used for chaining method calls.
public Transaction set (DocumentReference documentRef, Object data, SetOptions options)
Writes to the document referred to by the provided DocumentReference. 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.
Parameters
documentRef | The DocumentReference to overwrite. |
---|---|
data | The data to write to the document (e.g. a Map or a POJO containing the desired document contents). |
options | An object to configure the set behavior. |
Returns
- This
Transaction
instance. Used for chaining method calls.
public Transaction update (DocumentReference documentRef, Map<String, Object> data)
Updates fields in the document referred to by the provided
DocumentReference
. If no document exists yet, the update will fail.
Parameters
documentRef | 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
Transaction
instance. Used for chaining method calls.
public Transaction update (DocumentReference documentRef, String field, Object value, Object... moreFieldsAndValues)
Updates fields in the document referred to by the provided
DocumentReference
. If no document exists yet, the update will fail.
Parameters
documentRef | The DocumentReference to update. |
---|---|
field | The first field to update. Fields can contain dots to reference a nested field within the document. |
value | The first value |
moreFieldsAndValues | Additional field/value pairs. |
Returns
- This
Transaction
instance. Used for chaining method calls.
public Transaction update (DocumentReference documentRef, FieldPath fieldPath, Object value, Object... moreFieldsAndValues)
Updates fields in the document referred to by the provided
DocumentReference
. If no document exists yet, the update will fail.
Parameters
documentRef | The DocumentReference to update. |
---|---|
fieldPath | The first field to update. |
value | The first value |
moreFieldsAndValues | Additional field/value pairs. |
Returns
- This
Transaction
instance. Used for chaining method calls.