set<T> method

void set<T>(
  1. DocumentReference<T> documentReference,
  2. T data
)

Write to the document referred to by the provided DocumentReference. If the document does not exist yet, it will be created.

Implementation

void set<T>(DocumentReference<T> documentReference, T data) {
  final firestoreData = documentReference._converter.toFirestore(data);

  _validateDocumentData(
    'data',
    firestoreData,
    allowDeletes: false,
  );

  _verifyNotCommited();

  final transform =
      _DocumentTransform.fromObject(documentReference, firestoreData);
  transform.validate();

  firestore1.Write op() {
    final document =
        DocumentSnapshot._fromObject(documentReference, firestoreData);

    final write = document._toWriteProto();
    if (transform.transforms.isNotEmpty) {
      write.updateTransforms = transform.toProto(firestore._serializer);
    }
    return write;
  }

  _operations.add((docPath: documentReference.path, op: op));
}