get<T> method

Future<DocumentSnapshot<T>> get<T>(
  1. DocumentReference<T> docRef
)

Reads the document referenced by the provided docRef.

If the document does not exist, the operation throws a FirebaseFirestoreAdminException with FirestoreClientErrorCode.notFound.

Implementation

Future<DocumentSnapshot<T>> get<T>(
  DocumentReference<T> docRef,
) async {
  assert(
    _transactionWriteBatch._operations.isEmpty,
    'Transactions require all reads to be executed before all writes.',
  );
  // return _firestore.doc(documentPath).get();
  final reader = _DocumentReader(
    firestore: _firestore,
    documents: [docRef],
    fieldMask: null,
    transactionId: _transactionId,
  );
  final tag = requestTag();
  final result = (await reader.get(tag)).single;

  if (!result.exists) {
    throw FirebaseFirestoreAdminException(FirestoreClientErrorCode.notFound);
  } else {
    return result;
  }
}