getDocSnapshotById method
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:
- getDocSnapshotByIdWithConverter typed snapshots
- getDocRefById reference access
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);
}