Writes to the document referred to by document. If the document doesn’t yet exist,
this method creates it and then sets the data. If the document exists, this method overwrites
the document data with the new values.
Writes to the document referred to by document. If the document doesn’t yet exist,
this method creates it and then sets the data. If you pass merge:true, the provided data will
be merged into any existing document.
A Dictionary that contains the fields and data to write to the document.
document
A reference to the document whose data should be overwritten.
merge
Whether to merge the provided data into any existing document. If enabled,
all omitted fields remain untouched. If your input sets any field to an empty dictionary, any
nested field is overwritten.
Return Value
This Transaction instance. Used for chaining method calls.
Writes to the document referred to by document and only replace the fields
specified under mergeFields. Any field that is not specified in mergeFields
is ignored and remains untouched. If the document doesn’t yet exist,
this method creates it and then sets the data.
It is an error to include a field in mergeFields that does not have a corresponding
value in the data dictionary.
A Dictionary containing the fields that make up the document
to be written.
document
A reference to the document whose data should be overwritten.
mergeFields
An Array that contains a list of String or FieldPath elements
specifying which fields to merge. Fields can contain dots to reference nested fields within
the document. If your input sets any field to an empty dictionary, any nested field is
overwritten.
Return Value
This Transaction instance. Used for chaining method calls.
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Missing the information I need","missingTheInformationINeed","thumb-down"],["Too complicated / too many steps","tooComplicatedTooManySteps","thumb-down"],["Out of date","outOfDate","thumb-down"],["Samples / code issue","samplesCodeIssue","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2025-03-11 UTC."],[],[],null,["# FirebaseFirestore Framework Reference\n\nFIRTransaction\n==============\n\n\n @interface FIRTransaction : NSObject\n\n`Transaction` provides methods to read and write data within a transaction. \nSee\n`Firestore.runTransaction(_:)`\n- `\n ``\n ``\n `\n\n ### [-setData:forDocument:](#/c:objc(cs)FIRTransaction(im)setData:forDocument:)\n\n `\n ` \n Writes to the document referred to by `document`. If the document doesn't yet exist,\n this method creates it and then sets the data. If the document exists, this method overwrites\n the document data with the new values. \n\n #### Declaration\n\n Objective-C \n\n - (nonnull FIRTransaction *)setData:(nonnull NSDictionary\u003cNSString *, id\u003e *)data\n forDocument:(nonnull ../Classes/FIRDocumentReference.html *)document;\n\n #### Parameters\n\n |------------------|----------------------------------------------------------------------------|\n | ` `*data*` ` | A `Dictionary` that contains the fields and data to write to the document. |\n | ` `*document*` ` | A reference to the document whose data should be overwritten. |\n\n #### Return Value\n\n This `Transaction` instance. Used for chaining method calls.\n- `\n ``\n ``\n `\n\n ### [-setData:forDocument:merge:](#/c:objc(cs)FIRTransaction(im)setData:forDocument:merge:)\n\n `\n ` \n Writes to the document referred to by `document`. If the document doesn't yet exist,\n this method creates it and then sets the data. If you pass `merge:true`, the provided data will\n be merged into any existing document. \n\n #### Declaration\n\n Objective-C \n\n - (nonnull FIRTransaction *)setData:(nonnull NSDictionary\u003cNSString *, id\u003e *)data\n forDocument:(nonnull ../Classes/FIRDocumentReference.html *)document\n merge:(BOOL)merge;\n\n #### Parameters\n\n |------------------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n | ` `*data*` ` | A `Dictionary` that contains the fields and data to write to the document. |\n | ` `*document*` ` | A reference to the document whose data should be overwritten. |\n | ` `*merge*` ` | Whether to merge the provided data into any existing document. If enabled, all omitted fields remain untouched. If your input sets any field to an empty dictionary, any nested field is overwritten. |\n\n #### Return Value\n\n This `Transaction` instance. Used for chaining method calls.\n- `\n ``\n ``\n `\n\n ### [-setData:forDocument:mergeFields:](#/c:objc(cs)FIRTransaction(im)setData:forDocument:mergeFields:)\n\n `\n ` \n Writes to the document referred to by `document` and only replace the fields\n specified under `mergeFields`. Any field that is not specified in `mergeFields`\n is ignored and remains untouched. If the document doesn't yet exist,\n this method creates it and then sets the data.\n\n It is an error to include a field in `mergeFields` that does not have a corresponding\n value in the `data` dictionary. \n\n #### Declaration\n\n Objective-C \n\n - (nonnull FIRTransaction *)setData:(nonnull NSDictionary\u003cNSString *, id\u003e *)data\n forDocument:(nonnull ../Classes/FIRDocumentReference.html *)document\n mergeFields:(nonnull NSArray\u003cid\u003e *)mergeFields;\n\n #### Parameters\n\n |---------------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n | ` `*data*` ` | A `Dictionary` containing the fields that make up the document to be written. |\n | ` `*document*` ` | A reference to the document whose data should be overwritten. |\n | ` `*mergeFields*` ` | An `Array` that contains a list of `String` or `FieldPath` elements specifying which fields to merge. Fields can contain dots to reference nested fields within the document. If your input sets any field to an empty dictionary, any nested field is overwritten. |\n\n #### Return Value\n\n This `Transaction` instance. Used for chaining method calls.\n- `\n ``\n ``\n `\n\n ### [-updateData:forDocument:](#/c:objc(cs)FIRTransaction(im)updateData:forDocument:)\n\n `\n ` \n Updates fields in the document referred to by `document`.\n If the document does not exist, the transaction will fail. \n\n #### Declaration\n\n Objective-C \n\n - (nonnull FIRTransaction *)updateData:(nonnull NSDictionary\u003cid, id\u003e *)fields\n forDocument:(nonnull ../Classes/FIRDocumentReference.html *)document;\n\n #### Parameters\n\n |------------------|------------------------------------------------------------------------------------------------------------------------------|\n | ` `*fields*` ` | A `Dictionary` containing the fields (expressed as an `String` or `FieldPath`) and values with which to update the document. |\n | ` `*document*` ` | A reference to the document whose data should be updated. |\n\n #### Return Value\n\n This `Transaction` instance. Used for chaining method calls.\n- `\n ``\n ``\n `\n\n ### [-deleteDocument:](#/c:objc(cs)FIRTransaction(im)deleteDocument:)\n\n `\n ` \n Deletes the document referred to by `document`. \n\n #### Declaration\n\n Objective-C \n\n - (nonnull FIRTransaction *)deleteDocument:\n (nonnull ../Classes/FIRDocumentReference.html *)document;\n\n #### Parameters\n\n |------------------|-----------------------------------------------------|\n | ` `*document*` ` | A reference to the document that should be deleted. |\n\n #### Return Value\n\n This `Transaction` instance. Used for chaining method calls.\n- `\n ``\n ``\n `\n\n ### [-getDocument:error:](#/c:objc(cs)FIRTransaction(im)getDocument:error:)\n\n `\n ` \n Reads the document referenced by `document`. \n\n #### Declaration\n\n Objective-C \n\n - (../Classes/FIRDocumentSnapshot.html *_Nullable)\n getDocument:(nonnull ../Classes/FIRDocumentReference.html *)document\n error:(NSError *_Nullable *_Nullable)error;\n\n #### Parameters\n\n |------------------|--------------------------------------------------------|\n | ` `*document*` ` | A reference to the document to be read. |\n | ` `*error*` ` | An out parameter to capture an error, if one occurred. |"]]