set<T> method

Transaction set<T>(
  1. DocumentReference<T> documentReference,
  2. T data, [
  3. SetOptions? options
])

Writes to the document referred to by the provided DocumentReference. If the document does not exist yet, it will be created. If you pass SetOptions, the provided data can be merged into the existing document.

Implementation

Transaction set<T>(
  DocumentReference<T> documentReference,
  T data, [
  SetOptions? options,
]) {
  assert(
    documentReference.firestore == _firestore,
    'the document provided is from a different Firestore instance',
  );

  Map<String, dynamic> firestoreData;
  if (documentReference is _JsonDocumentReference) {
    firestoreData = data as Map<String, dynamic>;
  } else {
    final withConverterDoc =
        documentReference as _WithConverterDocumentReference<T>;
    firestoreData = withConverterDoc._toFirestore(data, options);
  }

  return Transaction._(
    _firestore,
    _delegate.set(
      documentReference.path,
      _CodecUtility.replaceValueWithDelegatesInMap(firestoreData)!,
      options,
    ),
  );
}