Class Transaction (2.3.1)

public sealed class Transaction

A transaction, as created by RunTransactionAsync<T>(Func<Transaction, Task<T>>, TransactionOptions, CancellationToken) (and overloads) and passed to user code.

Inheritance

Object > Transaction

Namespace

Google.Cloud.Firestore

Assembly

Google.Cloud.Firestore.dll

Properties

CancellationToken

public CancellationToken CancellationToken { get; }

The cancellation token for this transaction

Property Value
TypeDescription
CancellationToken

Database

public FirestoreDb Database { get; }

The database for this transaction.

Property Value
TypeDescription
FirestoreDb

Methods

Create(DocumentReference, Object)

public void Create(DocumentReference documentReference, object documentData)

Adds an operation to create a document in this transaction.

Parameters
NameDescription
documentReferenceDocumentReference

The document reference to create. Must not be null.

documentDataObject

The data for the document. Must not be null.

Delete(DocumentReference, Precondition)

public void Delete(DocumentReference documentReference, Precondition precondition = null)

Adds an operation to delete a document's data in this transaction.

Parameters
NameDescription
documentReferenceDocumentReference

The document to delete. Must not be null.

preconditionPrecondition

Optional precondition for deletion. May be null, in which case the deletion is unconditional.

GetAllSnapshotsAsync(IEnumerable<DocumentReference>, FieldMask, CancellationToken)

public Task<IList<DocumentSnapshot>> GetAllSnapshotsAsync(IEnumerable<DocumentReference> documentReferences, FieldMask fieldMask, CancellationToken cancellationToken = default(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.

Parameters
NameDescription
documentReferencesIEnumerable<DocumentReference>

The document references to fetch. Must not be null, or contain null references.

fieldMaskFieldMask

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.

cancellationTokenCancellationToken

A cancellation token to monitor for the asynchronous operation.

Returns
TypeDescription
Task<IList<DocumentSnapshot>>

The document snapshots, in the same order as documentReferences.

Remarks

Any documents which are missing are represented in the returned list by a DocumentSnapshot with Exists value of false.

GetAllSnapshotsAsync(IEnumerable<DocumentReference>, CancellationToken)

public Task<IList<DocumentSnapshot>> GetAllSnapshotsAsync(IEnumerable<DocumentReference> documentReferences, CancellationToken cancellationToken = default(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.

Parameters
NameDescription
documentReferencesIEnumerable<DocumentReference>

The document references to fetch. Must not be null, or contain null references.

cancellationTokenCancellationToken

A cancellation token to monitor for the asynchronous operation.

Returns
TypeDescription
Task<IList<DocumentSnapshot>>

The document snapshots, in the same order as documentReferences.

Remarks

Any documents which are missing are represented in the returned list by a DocumentSnapshot with Exists value of false.

GetSnapshotAsync(DocumentReference, CancellationToken)

public Task<DocumentSnapshot> GetSnapshotAsync(DocumentReference documentReference, CancellationToken cancellationToken = default(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.

Parameters
NameDescription
documentReferenceDocumentReference

The document reference to fetch. Must not be null.

cancellationTokenCancellationToken

A cancellation token to monitor for the asynchronous operation.

Returns
TypeDescription
Task<DocumentSnapshot>

A snapshot of the given document with respect to this transaction.

GetSnapshotAsync(Query, CancellationToken)

public Task<QuerySnapshot> GetSnapshotAsync(Query query, CancellationToken cancellationToken = default(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.

Parameters
NameDescription
queryQuery

The query to execute. Must not be null.

cancellationTokenCancellationToken

A cancellation token to monitor for the asynchronous operation.

Returns
TypeDescription
Task<QuerySnapshot>

A snapshot of results of the given query with respect to this transaction.

Set(DocumentReference, Object, SetOptions)

public void Set(DocumentReference documentReference, object documentData, SetOptions options = null)

Adds an operation to set a document's data in this transaction.

Parameters
NameDescription
documentReferenceDocumentReference

The document in which to set the data. Must not be null.

documentDataObject

The data for the document. Must not be null.

optionsSetOptions

The options to use when updating the document. May be null, which is equivalent to Overwrite.

Update(DocumentReference, IDictionary<FieldPath, Object>, Precondition)

public void Update(DocumentReference documentReference, IDictionary<FieldPath, object> updates, Precondition precondition = null)

Adds an operation to update a document's data in this transaction.

Parameters
NameDescription
documentReferenceDocumentReference

The document to update. Must not be null.

updatesIDictionary<FieldPath, Object>

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.

preconditionPrecondition

Optional precondition for updating the document. May be null, which is equivalent to MustExist.

Update(DocumentReference, IDictionary<String, Object>, Precondition)

public void Update(DocumentReference documentReference, IDictionary<string, object> updates, Precondition precondition = null)

Adds an operation to update a document's data in this transaction.

Parameters
NameDescription
documentReferenceDocumentReference

A document reference indicating the path of the document to update. Must not be null.

updatesIDictionary<String, Object>

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.

preconditionPrecondition

Optional precondition for updating the document. May be null, which is equivalent to MustExist.

Update(DocumentReference, String, Object, Precondition)

public void Update(DocumentReference documentReference, string field, object value, Precondition precondition = null)

Adds an operation to update a document's data in this transaction.

Parameters
NameDescription
documentReferenceDocumentReference

A document reference indicating the path of the document to update. Must not be null.

fieldString

The dot-separated name of the field to update. Must not be null.

valueObject

The new value for the field. May be null.

preconditionPrecondition

Optional precondition for updating the document. May be null, which is equivalent to MustExist.