collection method

CollectionReference<DocumentData> collection(
  1. String collectionPath
)

Gets a CollectionReference instance that refers to the collection at the specified path.

  • collectionPath: A slash-separated path to a collection.

Returns CollectionReference A reference to the new sub-collection.

Implementation

CollectionReference<DocumentData> collection(String collectionPath) {
  _validateResourcePath('collectionPath', collectionPath);

  final path = _ResourcePath.empty._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._(
    firestore: this,
    path: path._toQualifiedResourcePath(app.projectId, _databaseId),
    converter: _jsonConverter,
  );
}