one<T> method

Future<bool> one<T>(
  1. dynamic object, {
  2. String? subcollection,
})

Checks if a document exists in Firestore using its type and ID.

Implementation

Future<bool> one<T>(dynamic object, { String? subcollection }) async {
  if (object.id == null) {
    return false;
  }
  DocumentReference ref = FS.instance.collection(object.runtimeType.toString()).doc(object.id);
  if (subcollection != null) {
    ref = FS.instance.collection(object.runtimeType.toString()).doc(subcollection).collection(subcollection).doc(object.id);
  }
  DocumentSnapshot snapshot = await ref.get();
  return snapshot.exists;
}