set<T> method

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

Writes to the document referred to by document.

If the document does not yet exist, it will be created.

If SetOptions are provided, the data will be merged into an existing document instead of overwriting.

Implementation

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

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

  return _delegate.set(
    document.path,
    _CodecUtility.replaceValueWithDelegatesInMap(firestoreData)!,
    options,
  );
}