getDocSnapshotByIdWithConverter method
Gets a document snapshot with type conversion
Returns DocumentSnapshot
with automatic conversion to type T
Useful for accessing metadata with typed data
Parameters:
id
unique identifier of the document
collectionPathOverride
override path for collection groups
Features:
- Automatic type conversion
- Metadata access
- Local ID field management
- Document reference handling
Example:
final snapshot = await api.getDocSnapshotByIdWithConverter<User>(id: 'user-123');
if (snapshot.exists) {
final user = snapshot.data();
print('Created at ${snapshot.metadata.creationTime}');
print('User name ${user.name}');
}
See also:
- getDocSnapshotById raw data snapshots
- getDocRefByIdWithConverter reference access
Implementation
Future<DocumentSnapshot<T>> getDocSnapshotByIdWithConverter({
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 docRefWithConverter = getDocRefByIdWithConverter(
id: id,
collectionPathOverride: collectionPathOverride,
);
_log.debug(
message: 'Finding doc snapshot with converter..',
sensitiveData: SensitiveData(
path: collectionPathOverride ?? _collectionPath(),
id: id,
),
);
return docRefWithConverter.get(_getOptions);
}