collection method

Pipeline collection(
  1. Object collection, {
  2. String? forceIndex,
  3. Map<String, Object?>? rawOptions,
})

Reads the documents of one collection: a slash-separated path (String) or a CollectionReference.

With forceIndex the server uses the index with that name.

Implementation

Pipeline collection(
  Object collection, {
  String? forceIndex,
  Map<String, Object?>? rawOptions,
}) {
  final String path;
  if (collection is CollectionReference) {
    _validateDatabase(
      collection.firestore.modelDatabaseId,
      'CollectionReference',
    );
    path = collection.path;
  } else if (collection is String) {
    path = collection;
  } else {
    throw ArgumentError(
      'collection() takes a path or a CollectionReference, but got: '
      '$collection',
    );
  }
  final ResourcePath resourcePath = _parsePath(path, 'collection');
  if (resourcePath.length.isEven) {
    throw ArgumentError(
      'Invalid collection path ($path). A collection path must have an '
      'odd number of segments.',
    );
  }
  return _start(
    Stage(
      'collection',
      args: <pb.Value Function(PipelineEncoder)>[
        (_) => relativeReferenceValue(resourcePath.canonicalString),
      ],
      options: _forceIndex(forceIndex),
      rawOptions: rawOptions,
    ),
  );
}