docExists method

Future<bool> docExists({
  1. required String id,
  2. String? collectionPathOverride,
})

Used to determined if a document exists based on given id.

Implementation

Future<bool> docExists({
  required String id,
  String? collectionPathOverride,
}) async {
  assert(
    _isCollectionGroup == (collectionPathOverride != null),
    'Firestore does not support finding a document by id when communicating with a collection group, '
    'therefore, you must specify the collectionPathOverride containing all parent collection and document ids '
    'in order to make this method work.',
  );
  final docRef =
      findDocRef(id: id, collectionPathOverride: collectionPathOverride);
  _log.info(
    message: 'Checking if document exists..',
    sensitiveData: _shouldNotSensitiveInfo
        ? null
        : SensitiveData(
            path: collectionPathOverride ?? _collectionPath(),
            id: id,
          ),
  );
  return (await docRef.get(_getOptions)).exists;
}