streamByDocId method
Streams a single document
Returns real-time updates for a specific document Provides raw Firestore data without conversion
Parameters:
id
unique identifier of the document
collectionPathOverride
override path for collection groups
Returns Stream of DocumentSnapshot
containing:
- Document data
- Document metadata
- Real-time updates
Features:
- Real-time updates
- Raw data access
- Local ID field management
- Document reference handling
Example:
final stream = api.streamByDocId(id: 'user-123');
stream.listen((snapshot) {
if (snapshot.exists) {
print('User data: ${snapshot.data()}');
}
});
See also: streamDocByIdWithConverter type-safe document streaming streamAll collection streaming
Implementation
Stream<DocumentSnapshot<Map<String, dynamic>>> streamByDocId({
required String id,
String? collectionPathOverride,
}) {
final path = collectionPathOverride ?? _collectionPath();
final docRef =
getDocRefById(id: id, collectionPathOverride: collectionPathOverride);
_log.debug(
message: 'Finding doc stream..',
sensitiveData: SensitiveData(
path: path,
id: id,
),
);
return docRef.snapshots().handleError(
(error, stackTrace) {
_log.error(
message: 'Error streaming document',
sensitiveData: SensitiveData(
path: path,
id: id,
),
error: error,
stackTrace: stackTrace,
);
throw TurboFirestoreException.fromFirestoreException(
error,
stackTrace,
path: path,
);
},
);
}