collection method
Gets a CollectionReference instance that refers to the collection at the specified path.
collectionPath
: A slash-separated path to a collection.
Returns A reference to the new subcollection.
final documentRef = firestore.doc('col/doc');
final subcollection = documentRef.collection('subcollection');
print('Path to subcollection: ${subcollection.path}');
Implementation
CollectionReference<DocumentData> collection(String collectionPath) {
_validateResourcePath('collectionPath', collectionPath);
final path = _path._append(collectionPath);
if (!path.isCollection) {
throw ArgumentError.value(
collectionPath,
'collectionPath',
'Value for argument "collectionPath" must point to a collection, but was '
'"$collectionPath". Your path does not contain an odd number of components.',
);
}
return CollectionReference<DocumentData>._(
firestore: firestore,
path: path,
converter: _jsonConverter,
);
}