A Firestore WriteBatch that can be used to atomically commit multiple write operations at once.
WriteBatch
Package
@google-cloud/firestore!Constructors
(constructor)(firestore)
constructor(firestore: Firestore);
Constructs a new instance of the WriteBatch
class
Name | Description |
firestore |
Firestore
|
Properties
_opCount
get _opCount(): number;
The number of writes in this batch.
Type | Description |
number |
isEmpty
get isEmpty(): boolean;
Checks if this write batch has any pending operations.
Type | Description |
boolean |
Methods
_commit(commitOptions)
_commit<Req extends api.ICommitRequest, Resp>(commitOptions?: {
transactionId?: Uint8Array;
requestTag?: string;
retryCodes?: number[];
methodName?: FirestoreUnaryMethod;
}): Promise<Resp>;
Commit method that takes an optional transaction ID.
Name | Description |
commitOptions |
{
transactionId?: Uint8Array;
requestTag?: string;
retryCodes?: number[];
methodName?: FirestoreUnaryMethod;
}
Options to use for this commit. |
Type | Description |
Promise<Resp> | A Promise that resolves when this batch completes. |
Name | Description |
Req | |
Resp |
_reset()
_reset(): void;
Resets the WriteBatch and dequeues all pending operations.
Type | Description |
void |
commit()
commit(): Promise<WriteResult[]>;
Atomically commits all pending operations to the database and verifies all preconditions. Fails the entire write if any precondition is not met.
Type | Description |
Promise<WriteResult[]> | {Promise.<Array.
|
create(documentRef, data)
create<T>(documentRef: firestore.DocumentReference<T>, data: T): WriteBatch;
Create a document with the provided object values. This will fail the batch if a document exists at its location.
Name | Description |
documentRef |
FirebaseFirestore.DocumentReference<T>
A reference to the document to be created. |
data |
T
The object to serialize as the document. |
Type | Description |
WriteBatch | {WriteBatch} This WriteBatch instance. Used for chaining method calls. |
Name | Description |
T |
delete(documentRef, precondition)
delete<T>(documentRef: firestore.DocumentReference<T>, precondition?: firestore.Precondition): WriteBatch;
Deletes a document from the database.
Name | Description |
documentRef |
FirebaseFirestore.DocumentReference<T>
A reference to the document to be deleted. |
precondition |
firestore.Precondition
A precondition to enforce for this delete. |
Type | Description |
WriteBatch | {WriteBatch} This WriteBatch instance. Used for chaining method calls. |
Name | Description |
T |
set(documentRef, data, options)
set<T>(documentRef: firestore.DocumentReference<T>, data: Partial<T>, options: firestore.SetOptions): WriteBatch;
Name | Description |
documentRef |
FirebaseFirestore.DocumentReference<T>
|
data |
Partial<T>
|
options |
firestore.SetOptions
|
Type | Description |
WriteBatch |
Name | Description |
T |
set(documentRef, data)
set<T>(documentRef: firestore.DocumentReference<T>, data: T): WriteBatch;
Name | Description |
documentRef |
FirebaseFirestore.DocumentReference<T>
|
data |
T
|
Type | Description |
WriteBatch |
Name | Description |
T |
set(documentRef, data, options)
set<T>(documentRef: firestore.DocumentReference<T>, data: T | Partial<T>, options?: firestore.SetOptions): WriteBatch;
Name | Description |
documentRef |
FirebaseFirestore.DocumentReference<T>
|
data |
T | Partial<T>
|
options |
firestore.SetOptions
|
Type | Description |
WriteBatch |
Name | Description |
T |
update(documentRef, dataOrField, preconditionOrValues)
update<T = firestore.DocumentData>(documentRef: firestore.DocumentReference<T>, dataOrField: firestore.UpdateData | string | firestore.FieldPath, ...preconditionOrValues: Array<{
lastUpdateTime?: firestore.Timestamp;
} | unknown | string | firestore.FieldPath>): WriteBatch;
Update fields of the document referred to by the provided [DocumentReference]DocumentReference. If the document doesn't yet exist, the update fails and the entire batch will be rejected.
The update() method accepts either an object with field paths encoded as keys and field values encoded as values, or a variable number of arguments that alternate between field paths and field values. Nested fields can be updated by providing dot-separated field path strings or by providing FieldPath objects.
A Precondition restricting this update can be specified as the last argument.
Name | Description |
documentRef |
FirebaseFirestore.DocumentReference<T>
A reference to the document to be updated. |
dataOrField |
FirebaseFirestore.UpdateData | string | FirebaseFirestore.FieldPath
An object containing the fields and values with which to update the document or the path of the first field to update. |
preconditionOrValues |
Array<{
lastUpdateTime?: FirebaseFirestore.Timestamp;
} | unknown | string | FirebaseFirestore.FieldPath>
An alternating list of field paths and values to update or a Precondition to restrict this update. |
Type | Description |
WriteBatch | {WriteBatch} This WriteBatch instance. Used for chaining method calls. |
Name | Description |
T |