collection method

CollectionReference<Map<String, Object?>> collection(
  1. String collectionPath
)

Returns a CollectionReference to the collection at collectionPath.

collectionPath is a slash-separated path from the root of the database with an odd number of segments, such as cities or cities/SF/landmarks. Throws an ArgumentError if it is empty or names a document (an even number of segments).

Creating a reference does not contact the backend, and the collection does not need to exist. The reference reads and writes Map<String, Object?> values; use CollectionReference.withConverter for your own type.

final CollectionReference<Map<String, Object?>> cities = firestore
    .collection('cities');
final QuerySnapshot<Map<String, Object?>> all = await cities.get();
print(all.length);

Implementation

CollectionReference<Map<String, Object?>> collection(String collectionPath) {
  checkNotNull(collectionPath, 'Provided collection path must not be null.');
  checkNonEmptyPath('Firestore.collection', collectionPath);
  final ResourcePath resourcePath = ResourcePath.fromString(collectionPath);
  return CollectionReferenceInternal.create<Map<String, Object?>>(
    resourcePath,
    this,
  );
}