Stay organized with collections
Save and categorize content based on your preferences.
Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License, and code samples are licensed under the Apache 2.0 License. For details, see the Google Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.
Last updated 2022-07-27 UTC.
[null,null,["Last updated 2022-07-27 UTC."],[],[],null,["- [firebase](/docs/reference/node/firebase).\n- [firestore](/docs/reference/node/firebase.firestore).\n- Transaction \nA reference to a transaction.\nThe `Transaction` object passed to a transaction's updateFunction provides\nthe methods to read and write data within the transaction context. See\n`Firestore.runTransaction()`.\n\nIndex\n\nConstructors\n\n- [constructor](/docs/reference/node/firebase.firestore.Transaction#constructor)\n\nMethods\n\n- [delete](/docs/reference/node/firebase.firestore.Transaction#delete)\n- [get](/docs/reference/node/firebase.firestore.Transaction#get)\n- [set](/docs/reference/node/firebase.firestore.Transaction#set)\n- [update](/docs/reference/node/firebase.firestore.Transaction#update)\n\nConstructors\n\nPrivate constructor\n\n- new Transaction ( ) : [Transaction](/docs/reference/node/firebase.firestore.Transaction)\n-\n\n Returns [Transaction](/docs/reference/node/firebase.firestore.Transaction)\n\nMethods\n\ndelete\n\n- delete ( documentRef : [DocumentReference](/docs/reference/node/firebase.firestore.DocumentReference) \\\u003c any \\\u003e ) : [Transaction](/docs/reference/node/firebase.firestore.Transaction)\n- Deletes the document referred to by the provided `DocumentReference`.\n\n Parameters\n -\n\n documentRef: [DocumentReference](/docs/reference/node/firebase.firestore.DocumentReference)\\\u003cany\\\u003e \n A reference to the document to be deleted.\n\n Returns [Transaction](/docs/reference/node/firebase.firestore.Transaction)\n\n This `Transaction` instance. Used for chaining method calls.\n\nget\n\n- get \\\u003c T \\\u003e ( documentRef : [DocumentReference](/docs/reference/node/firebase.firestore.DocumentReference) \\\u003c T \\\u003e ) : Promise \\\u003c [DocumentSnapshot](/docs/reference/node/firebase.firestore.DocumentSnapshot) \\\u003c T \\\u003e \\\u003e\n- Reads the document referenced by the provided `DocumentReference.`\n\n Type parameters\n -\n\n T\n\n Parameters\n -\n\n documentRef: [DocumentReference](/docs/reference/node/firebase.firestore.DocumentReference)\\\u003cT\\\u003e \n A reference to the document to be read.\n\n Returns Promise\\\u003c[DocumentSnapshot](/docs/reference/node/firebase.firestore.DocumentSnapshot)\\\u003cT\\\u003e\\\u003e\n\n A DocumentSnapshot for the read data.\n\nset\n\n- set \\\u003c T \\\u003e ( documentRef : [DocumentReference](/docs/reference/node/firebase.firestore.DocumentReference) \\\u003c T \\\u003e , data : Partial \\\u003c T \\\u003e , options : [SetOptions](/docs/reference/node/firebase.firestore.SetOptions) ) : [Transaction](/docs/reference/node/firebase.firestore.Transaction)\n- Writes to the document referred to by the provided `DocumentReference`.\n If the document does not exist yet, it will be created. If you pass\n `SetOptions`, the provided data can be merged into the existing document.\n\n Type parameters\n -\n\n T\n\n Parameters\n -\n\n documentRef: [DocumentReference](/docs/reference/node/firebase.firestore.DocumentReference)\\\u003cT\\\u003e \n A reference to the document to be set.\n -\n\n data: Partial\\\u003cT\\\u003e \n An object of the fields and values for the document.\n -\n\n options: [SetOptions](/docs/reference/node/firebase.firestore.SetOptions) \n An object to configure the set behavior.\n\n Returns [Transaction](/docs/reference/node/firebase.firestore.Transaction)\n\n This `Transaction` instance. Used for chaining method calls.\n- set \\\u003c T \\\u003e ( documentRef : [DocumentReference](/docs/reference/node/firebase.firestore.DocumentReference) \\\u003c T \\\u003e , data : T ) : [Transaction](/docs/reference/node/firebase.firestore.Transaction)\n- Writes to the document referred to by the provided `DocumentReference`.\n If the document does not exist yet, it will be created. If you pass\n `SetOptions`, the provided data can be merged into the existing document.\n\n Type parameters\n -\n\n T\n\n Parameters\n -\n\n documentRef: [DocumentReference](/docs/reference/node/firebase.firestore.DocumentReference)\\\u003cT\\\u003e \n A reference to the document to be set.\n -\n\n data: T \n An object of the fields and values for the document.\n\n Returns [Transaction](/docs/reference/node/firebase.firestore.Transaction)\n\n This `Transaction` instance. Used for chaining method calls.\n\nupdate\n\n- update ( documentRef : [DocumentReference](/docs/reference/node/firebase.firestore.DocumentReference) \\\u003c any \\\u003e , data : [UpdateData](/docs/reference/node/firebase.firestore#updatedata) ) : [Transaction](/docs/reference/node/firebase.firestore.Transaction)\n- Updates fields in the document referred to by the provided\n `DocumentReference`. The update will fail if applied to a document that\n does not exist.\n\n Parameters\n -\n\n documentRef: [DocumentReference](/docs/reference/node/firebase.firestore.DocumentReference)\\\u003cany\\\u003e \n A reference to the document to be updated.\n -\n\n data: [UpdateData](/docs/reference/node/firebase.firestore#updatedata) \n An object containing the fields and values with which to\n update the document. Fields can contain dots to reference nested fields\n within the document.\n\n Returns [Transaction](/docs/reference/node/firebase.firestore.Transaction)\n\n This `Transaction` instance. Used for chaining method calls.\n- update ( documentRef : [DocumentReference](/docs/reference/node/firebase.firestore.DocumentReference) \\\u003c any \\\u003e , field : string \\| [FieldPath](/docs/reference/node/firebase.firestore.FieldPath) , value : any , ... moreFieldsAndValues : any \\[\\] ) : [Transaction](/docs/reference/node/firebase.firestore.Transaction)\n- Updates fields in the document referred to by the provided\n `DocumentReference`. The update will fail if applied to a document that\n does not exist.\n\n Nested fields can be updated by providing dot-separated field path\n strings or by providing FieldPath objects.\n\n Parameters\n -\n\n documentRef: [DocumentReference](/docs/reference/node/firebase.firestore.DocumentReference)\\\u003cany\\\u003e \n A reference to the document to be updated.\n -\n\n field: string \\| [FieldPath](/docs/reference/node/firebase.firestore.FieldPath) \n The first field to update.\n -\n\n value: any \n The first value.\n -\n\n Rest ...moreFieldsAndValues: any\\[\\] \n Additional key/value pairs.\n\n Returns [Transaction](/docs/reference/node/firebase.firestore.Transaction)\n\n A Promise resolved once the data has been successfully written\nto the backend (Note that it won't resolve while you're offline)."]]
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. SeeFirestore.runTransaction()
.