Firestore API - Class WriteBatch (3.4.0)

public sealed class WriteBatch

Reference documentation and code samples for the Firestore API class WriteBatch.

A batch of write operations, to be applied in a single commit.

Inheritance

object > WriteBatch

Namespace

Google.Cloud.Firestore

Assembly

Google.Cloud.Firestore.dll

Methods

CommitAsync(CancellationToken)

public Task<IList<WriteResult>> CommitAsync(CancellationToken cancellationToken = default)

Commits the batch on the server.

Parameter
NameDescription
cancellationTokenCancellationToken
Returns
TypeDescription
TaskIListWriteResult

The write results from the commit.

Create(DocumentReference, object)

public WriteBatch Create(DocumentReference documentReference, object documentData)

Adds a write operation which will create the specified document with a precondition that it doesn't exist already.

Parameters
NameDescription
documentReferenceDocumentReference

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

documentDataobject

The data for the document. Must not be null.

Returns
TypeDescription
WriteBatch

This batch, for the purpose of method chaining

Delete(DocumentReference, Precondition)

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

Adds a write operation that deletes the specified document, with an optional precondition.

Parameters
NameDescription
documentReferenceDocumentReference

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

preconditionPrecondition

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

Returns
TypeDescription
WriteBatch

This batch, for the purposes of method chaining.

Set(DocumentReference, object, SetOptions)

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

Adds an operation that sets data in a document, either replacing it completely or merging fields.

Parameters
NameDescription
documentReferenceDocumentReference

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

documentDataobject

The data to store in the document. Must not be null.

optionsSetOptions

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

Returns
TypeDescription
WriteBatch

This batch, for the purposes of method chaining.

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

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

Adds an update operation that updates just the specified fields paths in the document, with the corresponding values.

Parameters
NameDescription
documentReferenceDocumentReference

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

updatesIDictionaryFieldPathobject

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.

Returns
TypeDescription
WriteBatch

This batch, for the purposes of method chaining.

Update(DocumentReference, IDictionary<string, object>, Precondition)

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

Adds an update operation that updates just the specified fields paths in the document, with the corresponding values.

Parameters
NameDescription
documentReferenceDocumentReference

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

updatesIDictionarystringobject

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.

Returns
TypeDescription
WriteBatch

This batch, for the purposes of method chaining.

Update(DocumentReference, string, object, Precondition)

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

Adds an update operation that updates just the specified field in the document, with the corresponding values.

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.

Returns
TypeDescription
WriteBatch

This batch, for the purposes of method chaining.