set<T extends Object?> method

WriteBatch set<T extends Object?>(
  1. DocumentReference<T> documentRef,
  2. T data, [
  3. 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

WriteBatch 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.');
  _verifyNotCommitted();
  final Map<String, Object?> rawData = toRawData<T>(
    data,
    documentRef.converter,
    options,
  );
  final UserDataParsedSetData parsed = setOptions.merge
      ? _firestore.dataConverter.parseMergeData(
          rawData,
          setOptions.fieldMask,
          methodName: 'WriteBatch.set',
          targetDoc: documentRef.key,
          hasConverter: documentRef.converter != null,
        )
      : _firestore.dataConverter.parseSetData(
          rawData,
          methodName: 'WriteBatch.set',
          targetDoc: documentRef.key,
          hasConverter: documentRef.converter != null,
        );
  _mutations.add(parsed.toMutation(documentRef.key, Precondition.none));
  return this;
}