set<T extends Object?> method
Transaction
set<T extends Object?>(
- DocumentReference<
T> documentRef, - T data, [
- SetOptions? options
Writes data to the document referred to by documentRef. If the
document does not exist yet, it is created. With merge options the
data is merged into the existing document.
Implementation
Transaction set<T extends Object?>(
DocumentReference<T> documentRef,
T data, [
SetOptions? options,
]) {
final SetOptions setOptions = options ?? const SetOptions();
_firestore.validateReference(documentRef);
checkNotNull<Object>(data, 'Provided data must not be null.');
final Map<String, Object?> rawData = toRawData<T>(
data,
documentRef.converter,
options,
);
final UserDataParsedSetData parsed = setOptions.merge
? _firestore.dataConverter.parseMergeData(
rawData,
setOptions.fieldMask,
methodName: 'Transaction.set',
targetDoc: documentRef.key,
hasConverter: documentRef.converter != null,
)
: _firestore.dataConverter.parseSetData(
rawData,
methodName: 'Transaction.set',
targetDoc: documentRef.key,
hasConverter: documentRef.converter != null,
);
_transaction.set(documentRef.key, parsed);
return this;
}