subcollection method

Pipeline subcollection(
  1. String path, {
  2. Map<String, Object?>? rawOptions,
})

Reads the documents of the subcollection path of the document that an enclosing pipeline is processing.

The returned pipeline cannot be executed on its own; use it as a subquery, with Pipeline.toArrayExpression or Pipeline.toScalarExpression:

firestore.pipeline().collection('books').addFields([
  firestore.pipeline().subcollection('reviews')
      .select(['stars']).toArrayExpression().as('stars'),
]);

Implementation

Pipeline subcollection(String path, {Map<String, Object?>? rawOptions}) {
  final ResourcePath resourcePath = _parsePath(path, 'subcollection');
  if (resourcePath.length.isEven) {
    throw ArgumentError(
      'Invalid subcollection path ($path). A collection path must have '
      'an odd number of segments.',
    );
  }
  return _start(
    Stage(
      'subcollection',
      args: <pb.Value Function(PipelineEncoder)>[
        (_) => stringValue(resourcePath.canonicalString),
      ],
      rawOptions: rawOptions,
    ),
  );
}