getDocSnapshotById method

Future<DocumentSnapshot<Map<String, dynamic>>> getDocSnapshotById({
  1. required String id,
  2. String? collectionPathOverride,
})

Gets a document snapshot for raw data access

Returns DocumentSnapshot containing raw document data and metadata Useful for accessing document metadata with data

Parameters: id unique identifier of the document collectionPathOverride override path for collection groups

Features:

  • Metadata access
  • Raw data access
  • Local ID field management
  • Document reference handling

Example:

final snapshot = await api.getDocSnapshotById(id: 'user-123');
if (snapshot.exists) {
  print('Created at ${snapshot.metadata.creationTime}');
  print('Data ${snapshot.data()}');
}

See also:

Implementation

Future<DocumentSnapshot<Map<String, dynamic>>> getDocSnapshotById({
  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 =
      getDocRefById(id: id, collectionPathOverride: collectionPathOverride);
  _log.debug(
    message: 'Finding document snapshot..',
    sensitiveData: SensitiveData(
      path: collectionPathOverride ?? _collectionPath(),
      id: id,
    ),
  );
  return docRef.get(_getOptions);
}