Class Transaction
A transaction, as created by RunTransactionAsync<T>(Func<Transaction, Task<T>>, TransactionOptions, CancellationToken) (and overloads) and passed to user code.
Namespace: Google.Cloud.Firestore
Assembly: Google.Cloud.Firestore.dll
Syntax
public sealed class Transaction
Properties
CancellationToken
The cancellation token for this transaction
Declaration
public CancellationToken CancellationToken { get; }
Property Value
Type | Description |
---|---|
CancellationToken |
Database
The database for this transaction.
Declaration
public FirestoreDb Database { get; }
Property Value
Type | Description |
---|---|
FirestoreDb |
Methods
Create(DocumentReference, object)
Adds an operation to create a document in this transaction.
Declaration
public void Create(DocumentReference documentReference, object documentData)
Parameters
Type | Name | Description |
---|---|---|
DocumentReference | documentReference | The document reference to create. Must not be null. |
object | documentData | The data for the document. Must not be null. |
Delete(DocumentReference, Precondition)
Adds an operation to delete a document's data in this transaction.
Declaration
public void Delete(DocumentReference documentReference, Precondition precondition = null)
Parameters
Type | Name | Description |
---|---|---|
DocumentReference | documentReference | The document to delete. Must not be null. |
Precondition | precondition | Optional precondition for deletion. May be null, in which case the deletion is unconditional. |
GetAllSnapshotsAsync(IEnumerable<DocumentReference>, FieldMask, CancellationToken)
Fetch snapshots of all the documents specified by documentReferences
, with respect to this transaction,
potentially limiting the fields returned.
This method cannot be called after any write operations have been created.
Declaration
public Task<IList<DocumentSnapshot>> GetAllSnapshotsAsync(IEnumerable<DocumentReference> documentReferences, FieldMask fieldMask, CancellationToken cancellationToken = default)
Parameters
Type | Name | Description |
---|---|---|
IEnumerable<DocumentReference> | documentReferences | The document references to fetch. Must not be null, or contain null references. |
FieldMask | fieldMask | The field mask to use to restrict which fields are retrieved. May be null, in which case no field mask is applied, and the complete documents are retrieved. |
CancellationToken | cancellationToken | A cancellation token to monitor for the asynchronous operation. |
Returns
Type | Description |
---|---|
Task<IList<DocumentSnapshot>> | The document snapshots, in the same order as |
Remarks
Any documents which are missing are represented in the returned list by a DocumentSnapshot
with Exists value of false
.
GetAllSnapshotsAsync(IEnumerable<DocumentReference>, CancellationToken)
Fetch snapshots of all the documents specified by documentReferences
, with respect to this transaction.
This method cannot be called after any write operations have been created.
Declaration
public Task<IList<DocumentSnapshot>> GetAllSnapshotsAsync(IEnumerable<DocumentReference> documentReferences, CancellationToken cancellationToken = default)
Parameters
Type | Name | Description |
---|---|---|
IEnumerable<DocumentReference> | documentReferences | The document references to fetch. Must not be null, or contain null references. |
CancellationToken | cancellationToken | A cancellation token to monitor for the asynchronous operation. |
Returns
Type | Description |
---|---|
Task<IList<DocumentSnapshot>> | The document snapshots, in the same order as |
Remarks
Any documents which are missing are represented in the returned list by a DocumentSnapshot
with Exists value of false
.
GetSnapshotAsync(AggregateQuery, CancellationToken)
Fetch the AggregateQuerySnapshot from the specified AggregateQuery.
Declaration
public Task<AggregateQuerySnapshot> GetSnapshotAsync(AggregateQuery query, CancellationToken cancellationToken = default)
Parameters
Type | Name | Description |
---|---|---|
AggregateQuery | query | The aggregate query to execute. Must not be null. |
CancellationToken | cancellationToken | A cancellation token to monitor for the asynchronous operation. |
Returns
Type | Description |
---|---|
Task<AggregateQuerySnapshot> | A AggregateQuerySnapshot of results of the given query with respect to this transaction. |
GetSnapshotAsync(DocumentReference, CancellationToken)
Fetch a snapshot of the document specified by documentReference
, with respect to this transaction.
This method cannot be called after any write operations have been created.
Declaration
public Task<DocumentSnapshot> GetSnapshotAsync(DocumentReference documentReference, CancellationToken cancellationToken = default)
Parameters
Type | Name | Description |
---|---|---|
DocumentReference | documentReference | The document reference to fetch. Must not be null. |
CancellationToken | cancellationToken | A cancellation token to monitor for the asynchronous operation. |
Returns
Type | Description |
---|---|
Task<DocumentSnapshot> | A snapshot of the given document with respect to this transaction. |
GetSnapshotAsync(Query, CancellationToken)
Performs a query and returned a snapshot of the the results, with respect to this transaction. This method cannot be called after any write operations have been created.
Declaration
public Task<QuerySnapshot> GetSnapshotAsync(Query query, CancellationToken cancellationToken = default)
Parameters
Type | Name | Description |
---|---|---|
Query | query | The query to execute. Must not be null. |
CancellationToken | cancellationToken | A cancellation token to monitor for the asynchronous operation. |
Returns
Type | Description |
---|---|
Task<QuerySnapshot> | A snapshot of results of the given query with respect to this transaction. |
Set(DocumentReference, object, SetOptions)
Adds an operation to set a document's data in this transaction.
Declaration
public void Set(DocumentReference documentReference, object documentData, SetOptions options = null)
Parameters
Type | Name | Description |
---|---|---|
DocumentReference | documentReference | The document in which to set the data. Must not be null. |
object | documentData | The data for the document. Must not be null. |
SetOptions | options | The options to use when updating the document. May be null, which is equivalent to Overwrite. |
Update(DocumentReference, IDictionary<FieldPath, object>, Precondition)
Adds an operation to update a document's data in this transaction.
Declaration
public void Update(DocumentReference documentReference, IDictionary<FieldPath, object> updates, Precondition precondition = null)
Parameters
Type | Name | Description |
---|---|---|
DocumentReference | documentReference | The document to update. Must not be null. |
IDictionary<FieldPath, object> | updates | The updates to perform on the document, keyed by the field path to update. Fields not present in this dictionary are not updated. Must not be null or empty. |
Precondition | precondition | Optional precondition for updating the document. May be null, which is equivalent to MustExist. |
Update(DocumentReference, IDictionary<string, object>, Precondition)
Adds an operation to update a document's data in this transaction.
Declaration
public void Update(DocumentReference documentReference, IDictionary<string, object> updates, Precondition precondition = null)
Parameters
Type | Name | Description |
---|---|---|
DocumentReference | documentReference | A document reference indicating the path of the document to update. Must not be null. |
IDictionary<string, object> | updates | The updates to perform on the document, keyed by the dot-separated field path to update. Fields not present in this dictionary are not updated. Must not be null or empty. |
Precondition | precondition | Optional precondition for updating the document. May be null, which is equivalent to MustExist. |
Update(DocumentReference, string, object, Precondition)
Adds an operation to update a document's data in this transaction.
Declaration
public void Update(DocumentReference documentReference, string field, object value, Precondition precondition = null)
Parameters
Type | Name | Description |
---|---|---|
DocumentReference | documentReference | A document reference indicating the path of the document to update. Must not be null. |
string | field | The dot-separated name of the field to update. Must not be null. |
object | value | The new value for the field. May be null. |
Precondition | precondition | Optional precondition for updating the document. May be null, which is equivalent to MustExist. |