collection method
Gets a CollectionReference instance that refers to the subcollection at the specified path relative to this document.
collectionPath a slash-separated relative path to a subcollection. Throws an ArgumentError if it is empty
or names a document instead of a collection.
Returns the CollectionReference instance, which reads raw maps.
final CollectionReference<Map<String, Object?>> landmarks = firestore
.doc('cities/SF')
.collection('landmarks');
await landmarks.add({'name': 'Golden Gate Bridge'});
Implementation
CollectionReference<Map<String, Object?>> collection(String collectionPath) {
checkNotNull(collectionPath, 'Provided collection path must not be null.');
checkNonEmptyPath('DocumentReference.collection', collectionPath);
return CollectionReferenceInternal.create<Map<String, Object?>>(
key.path.appendField(ResourcePath.fromString(collectionPath)),
firestore,
);
}