docs-devsite/firestore_lite.transaction.md
Project: /docs/reference/js/_project.yaml Book: /docs/reference/_book.yaml page_type: reference
{% comment %} DO NOT EDIT THIS FILE! This is generated by the JS SDK team, and any local changes will be overwritten. Changes should be made in the source code at https://github.com/firebase/firebase-js-sdk {% endcomment %}
A reference to a transaction.
The Transaction object passed to a transaction's updateFunction provides the methods to read and write data within the transaction context. See runTransaction()<!-- -->.
<b>Signature:</b>
export declare class Transaction
| Method | Modifiers | Description |
|---|---|---|
| delete(documentRef) | Deletes the document referred to by the provided DocumentReference<!-- -->. | |
| get(documentRef) | Reads the document referenced by the provided DocumentReference<!-- -->. | |
| set(documentRef, data) | Writes to the document referred to by the provided DocumentReference<!-- -->. If the document does not exist yet, it will be created. | |
| set(documentRef, data, options) | Writes to the document referred to by the provided DocumentReference<!-- -->. If the document does not exist yet, it will be created. If you provide <code>merge</code> or <code>mergeFields</code>, the provided data can be merged into an existing document. | |
| update(documentRef, data) | Updates fields in the document referred to by the provided DocumentReference<!-- -->. The update will fail if applied to a document that does not exist. | |
| update(documentRef, field, value, moreFieldsAndValues) | Updates fields in the document referred to by the provided DocumentReference<!-- -->. The update will fail if applied to a document that does not exist.<!-- -->Nested fields can be updated by providing dot-separated field path strings or by providing <code>FieldPath</code> objects. |
Deletes the document referred to by the provided DocumentReference<!-- -->.
<b>Signature:</b>
delete<AppModelType, DbModelType extends DocumentData>(documentRef: DocumentReference<AppModelType, DbModelType>): this;
| Parameter | Type | Description |
|---|---|---|
| documentRef | DocumentReference<!-- --><AppModelType, DbModelType> | A reference to the document to be deleted. |
<b>Returns:</b>
this
This Transaction instance. Used for chaining method calls.
Reads the document referenced by the provided DocumentReference<!-- -->.
<b>Signature:</b>
get<AppModelType, DbModelType extends DocumentData>(documentRef: DocumentReference<AppModelType, DbModelType>): Promise<DocumentSnapshot<AppModelType, DbModelType>>;
| Parameter | Type | Description |
|---|---|---|
| documentRef | DocumentReference<!-- --><AppModelType, DbModelType> | A reference to the document to be read. |
<b>Returns:</b>
Promise<DocumentSnapshot<!-- --><AppModelType, DbModelType>>
A DocumentSnapshot with the read data.
Writes to the document referred to by the provided DocumentReference<!-- -->. If the document does not exist yet, it will be created.
<b>Signature:</b>
set<AppModelType, DbModelType extends DocumentData>(documentRef: DocumentReference<AppModelType, DbModelType>, data: WithFieldValue<AppModelType>): this;
| Parameter | Type | Description |
|---|---|---|
| documentRef | DocumentReference<!-- --><AppModelType, DbModelType> | A reference to the document to be set. |
| data | WithFieldValue<!-- --><AppModelType> | An object of the fields and values for the document. |
<b>Returns:</b>
this
This Transaction instance. Used for chaining method calls.
Error - If the provided input is not a valid Firestore document.
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.
<b>Signature:</b>
set<AppModelType, DbModelType extends DocumentData>(documentRef: DocumentReference<AppModelType, DbModelType>, data: PartialWithFieldValue<AppModelType>, options: SetOptions): this;
| Parameter | Type | Description |
|---|---|---|
| documentRef | DocumentReference<!-- --><AppModelType, DbModelType> | A reference to the document to be set. |
| data | PartialWithFieldValue<!-- --><AppModelType> | An object of the fields and values for the document. |
| options | SetOptions | An object to configure the set behavior. |
<b>Returns:</b>
this
This Transaction instance. Used for chaining method calls.
Error - If the provided input is not a valid Firestore document.
Updates fields in the document referred to by the provided DocumentReference<!-- -->. The update will fail if applied to a document that does not exist.
<b>Signature:</b>
update<AppModelType, DbModelType extends DocumentData>(documentRef: DocumentReference<AppModelType, DbModelType>, data: UpdateData<DbModelType>): this;
| Parameter | Type | Description |
|---|---|---|
| documentRef | DocumentReference<!-- --><AppModelType, DbModelType> | A reference to the document to be updated. |
| data | UpdateData<!-- --><DbModelType> | An object containing the fields and values with which to update the document. Fields can contain dots to reference nested fields within the document. |
<b>Returns:</b>
this
This Transaction instance. Used for chaining method calls.
Error - If the provided input is not valid Firestore data.
Updates fields in the document referred to by the provided DocumentReference<!-- -->. The update will fail if applied to a document that does not exist.
Nested fields can be updated by providing dot-separated field path strings or by providing FieldPath objects.
<b>Signature:</b>
update<AppModelType, DbModelType extends DocumentData>(documentRef: DocumentReference<AppModelType, DbModelType>, field: string | FieldPath, value: unknown, ...moreFieldsAndValues: unknown[]): this;
| Parameter | Type | Description |
|---|---|---|
| documentRef | DocumentReference<!-- --><AppModelType, DbModelType> | A reference to the document to be updated. |
| field | string | FieldPath | The first field to update. |
| value | unknown | The first value. |
| moreFieldsAndValues | unknown[] | Additional key/value pairs. |
<b>Returns:</b>
this
This Transaction instance. Used for chaining method calls.
Error - If the provided input is not valid Firestore data.