collectionGroup method

CollectionGroup<DocumentData> collectionGroup(
  1. String collectionId
)

Creates and returns a new Query that includes all documents in the database that are contained in a collection or subcollection with the given collectionId.

  • collectionId Identifies the collections to query over. Every collection or subcollection with this ID as the last segment of its path will be included. Cannot contain a slash.
final docA = await firestore.doc('my-group/docA').set({foo: 'bar'});
final docB = await firestore.doc('abc/def/my-group/docB').set({foo: 'bar'});

final query = firestore.collectionGroup('my-group')
   .where('foo', WhereOperator.equal 'bar');
final snapshot = await query.get();
print('Found ${snapshot.size} documents.');

Implementation

CollectionGroup<DocumentData> collectionGroup(String collectionId) {
  if (collectionId.contains('/')) {
    throw ArgumentError.value(
      collectionId,
      'collectionId',
      'Invalid collectionId "$collectionId". Collection IDs must not contain "/".',
    );
  }

  return CollectionGroup._(
    collectionId,
    firestore: this,
    converter: _jsonConverter,
  );
}