Skip to content

Commit 2406f6a

Browse files
docs: expand documentation on transactions (#1539)
1 parent 525275b commit 2406f6a

File tree

2 files changed

+43
-7
lines changed

2 files changed

+43
-7
lines changed

dev/src/index.ts

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -937,8 +937,22 @@ export class Firestore implements firestore.Firestore {
937937
* the transaction.
938938
*
939939
* You can use the transaction object passed to 'updateFunction' to read and
940-
* modify Firestore documents under lock. Transactions are committed once
941-
* 'updateFunction' resolves and attempted up to five times on failure.
940+
* modify Firestore documents under lock. You have to perform all reads before
941+
* before you perform any write.
942+
*
943+
* Documents read during a transaction are locked pessimistically. A
944+
* transaction's lock on a document blocks other transactions, batched
945+
* writes, and other non-transactional writes from changing that document.
946+
* A transaction releases its document locks at commit time or once it times
947+
* out or fails for any reason.
948+
*
949+
* Transactions are committed once 'updateFunction' resolves. If a transaction
950+
* fails with contention, the transaction is retried up to five times. The
951+
* `updateFunction` is invoked once for each attempt.
952+
*
953+
* Transactions time out after 60 seconds if no documents are read.
954+
* Transactions that are not committed within than 270 seconds are also
955+
* aborted.
942956
*
943957
* @template T
944958
* @param {Firestore~updateFunction} updateFunction The user function to

types/firestore.d.ts

Lines changed: 27 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,17 @@ declare namespace FirebaseFirestore {
2828
export type DocumentData = {[field: string]: any};
2929

3030
/**
31-
* Update data (for use with `DocumentReference.update()`) consists of field
32-
* paths (e.g. 'foo' or 'foo.baz') mapped to values. Fields that contain dots
33-
* reference nested fields within the document.
31+
* Update data (for use with [update]{@link DocumentReference#update})
32+
* that contains paths mapped to values. Fields that contain dots reference
33+
* nested fields within the document.
34+
*
35+
* You can update a top-level field in your document by using the field name
36+
* as a key (e.g. `foo`). The provided value completely replaces the contents
37+
* for this field.
38+
*
39+
* You can also update a nested field directly by using its field path as a
40+
* key (e.g. `foo.bar`). This nested field update replaces the contents at
41+
* `bar` but does not modify other data under `foo`.
3442
*/
3543
export type UpdateData = {[fieldPath: string]: any};
3644

@@ -300,8 +308,22 @@ declare namespace FirebaseFirestore {
300308
* the transaction.
301309
*
302310
* You can use the transaction object passed to 'updateFunction' to read and
303-
* modify Firestore documents under lock. Transactions are committed once
304-
* 'updateFunction' resolves and attempted up to five times on failure.
311+
* modify Firestore documents under lock. You have to perform all reads
312+
* before before you perform any write.
313+
*
314+
* Documents read during a transaction are locked pessimistically. A
315+
* transaction's lock on a document blocks other transactions, batched
316+
* writes, and other non-transactional writes from changing that document.
317+
* A transaction releases its document locks at commit time or once it times
318+
* out or fails for any reason.
319+
*
320+
* Transactions are committed once 'updateFunction' resolves. If a
321+
* transaction fails with contention, the transaction is retried up to five
322+
* times. The `updateFunction` is invoked once for each attempt.
323+
*
324+
* Transactions time out after 60 seconds if no documents are read.
325+
* Transactions that are not committed within than 270 seconds are also
326+
* aborted.
305327
*
306328
* @param updateFunction The function to execute within the transaction
307329
* context.

0 commit comments

Comments
 (0)