Hi there! Are you looking for the official Deno documentation? Try docs.deno.com for all your Deno learning needs.

WriteBatch

A write batch, used to perform multiple writes as a single atomic unit.

A WriteBatch object can be acquired by calling writeBatch. It provides methods for adding writes to the write batch. None of the writes will be committed (or visible locally) until WriteBatch.commit is called.

class WriteBatch {
private constructor();
commit(): Promise<void>;
delete<AppModelType, DbModelType extends DocumentData>(documentRef: DocumentReference<AppModelType, DbModelType>): WriteBatch;
set<AppModelType, DbModelType extends DocumentData>(documentRef: DocumentReference<AppModelType, DbModelType>, data: WithFieldValue<AppModelType>): WriteBatch;
set<AppModelType, DbModelType extends DocumentData>(
documentRef: DocumentReference<AppModelType, DbModelType>,
data: PartialWithFieldValue<AppModelType>,
options: SetOptions,
): WriteBatch;
update<AppModelType, DbModelType extends DocumentData>(documentRef: DocumentReference<AppModelType, DbModelType>, data: UpdateData<DbModelType>): WriteBatch;
update<AppModelType, DbModelType extends DocumentData>(
documentRef: DocumentReference<AppModelType, DbModelType>,
field: string | FieldPath,
value: unknown,
...moreFieldsAndValues: unknown[],
): WriteBatch;
}

§Constructors

§
new WriteBatch() private
[src]

§Methods

§
commit(): Promise<void>
[src]

Commits all of the writes in this write batch as a single atomic unit.

The result of these writes will only be reflected in document reads that occur after the returned promise resolves. If the client is offline, the write fails. If you would like to see local modifications or buffer writes until the client is online, use the full Firestore SDK.

@return

A Promise resolved once all of the writes in the batch have been successfully written to the backend as an atomic unit (note that it won't resolve while you're offline).

§
delete<AppModelType, DbModelType extends DocumentData>(documentRef: DocumentReference<AppModelType, DbModelType>): WriteBatch
[src]

Deletes the document referred to by the provided DocumentReference.

@param documentRef
  • A reference to the document to be deleted.
@return

This WriteBatch instance. Used for chaining method calls.

§
set<AppModelType, DbModelType extends DocumentData>(documentRef: DocumentReference<AppModelType, DbModelType>, data: WithFieldValue<AppModelType>): WriteBatch
[src]

Writes to the document referred to by the provided DocumentReference. If the document does not exist yet, it will be created.

@param documentRef
  • A reference to the document to be set.
@param data
  • An object of the fields and values for the document.
@return

This WriteBatch instance. Used for chaining method calls.

set<AppModelType, DbModelType extends DocumentData>(documentRef: DocumentReference<AppModelType, DbModelType>, data: PartialWithFieldValue<AppModelType>, options: SetOptions): WriteBatch
[src]

Writes to the document referred to by the provided DocumentReference. If the document does not exist yet, it will be created. If you provide merge or mergeFields, the provided data can be merged into an existing document.

@param documentRef
  • A reference to the document to be set.
@param data
  • An object of the fields and values for the document.
@param options
  • An object to configure the set behavior.
@return

This WriteBatch instance. Used for chaining method calls.

§
update<AppModelType, DbModelType extends DocumentData>(documentRef: DocumentReference<AppModelType, DbModelType>, data: UpdateData<DbModelType>): WriteBatch
[src]

Updates fields in the document referred to by the provided DocumentReference. The update will fail if applied to a document that does not exist.

@param documentRef
  • A reference to the document to be updated.
@param data
  • An object containing the fields and values with which to update the document. Fields can contain dots to reference nested fields within the document.
@return

This WriteBatch instance. Used for chaining method calls.

update<AppModelType, DbModelType extends DocumentData>(documentRef: DocumentReference<AppModelType, DbModelType>, field: string | FieldPath, value: unknown, ...moreFieldsAndValues: unknown[]): WriteBatch
[src]

Updates fields in the document referred to by this DocumentReference. The update will fail if applied to a document that does not exist.

Nested fields can be update by providing dot-separated field path strings or by providing FieldPath objects.

@param documentRef
  • A reference to the document to be updated.
@param field
  • The first field to update.
@param value
  • The first value.
@param moreFieldsAndValues
  • Additional key value pairs.
@return

This WriteBatch instance. Used for chaining method calls.