runTransaction<T extends JSAny> method

JSPromise<T> runTransaction<T extends JSAny>(
  1. JSFunction updateFunction, [
  2. JSObject transactionOptions
])

Executes the given updateFunction and commits the changes applied within the transaction.

You can use the transaction object passed to 'updateFunction' to read and modify Firestore documents under lock. You have to perform all reads before you perform any write.

Transactions can be performed as read-only or read-write transactions. By default, transactions are executed in read-write mode.

A read-write transaction obtains a pessimistic lock on all documents that are read during the transaction. These locks block other transactions, batched writes, and other non-transactional writes from changing that document. Any writes in a read-write transactions are committed once 'updateFunction' resolves, which also releases all locks.

If a read-write transaction fails with contention, the transaction is retried up to five times. The updateFunction is invoked once for each attempt.

Read-only transactions do not lock documents. They can be used to read documents at a consistent snapshot in time, which may be up to 60 seconds in the past. Read-only transactions are not retried.

Transactions time out after 60 seconds if no documents are read. Transactions that are not committed within than 270 seconds are also aborted. Any remaining locks are released when a transaction times out.

@param updateFunction The function to execute within the transaction context. @param transactionOptions Transaction options. @return If the transaction completed successfully or was explicitly aborted (by the updateFunction returning a failed Promise), the Promise returned by the updateFunction will be returned here. Else if the transaction failed, a rejected Promise with the corresponding failure error will be returned.

Implementation

external JSPromise<T> runTransaction<T extends JSAny>(
  JSFunction updateFunction, [
  JSObject transactionOptions,
]);