Partitions a query by returning partition cursors that can be used to run the query in parallel. The returned cursors are split points that can be used as starting and end points for individual query invocations.
Parameter
Name
Description
desiredPartitionCount
number
The desired maximum number of partition points. The number must be strictly positive. The actual number of partitions returned may be fewer. {AsyncIterable
Applies a custom data converter to thisCollectionGroup, allowing you to use your own custom model objects with Firestore. When you call get() on the returnedCollectionGroup, the provided converter will convert between Firestore data of typeNewDbModelTypeand your custom typeNewAppModelType.
Using the converter allows you to specify generic type arguments when storing and retrieving objects from Firestore.
Passing innullas the converter parameter removes the current converter.
Parameter
Name
Description
converter
null
Converts objects to and from Firestore. Passing innullremoves the current converter. {CollectionGroup} ACollectionGroupthat uses the provided converter.
classPost{constructor(readonlytitle:string,readonlyauthor:string){}toString():string{returnthis.title+', by '+this.author;}}constpostConverter={toFirestore(post:Post):FirebaseFirestore.DocumentData{return{title:post.title,author:post.author};},fromFirestore(snapshot:FirebaseFirestore.QueryDocumentSnapshot):Post{constdata=snapshot.data();returnnewPost(data.title,data.author);}};constquerySnapshot=awaitFirestore().collectionGroup('posts').withConverter(postConverter).get();for(constdocofquerySnapshot.docs){constpost=doc.data();post.title;// stringpost.toString();// Should be definedpost.someNonExistentProperty;// TS error}
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Hard to understand","hardToUnderstand","thumb-down"],["Incorrect information or sample code","incorrectInformationOrSampleCode","thumb-down"],["Missing the information/samples I need","missingTheInformationSamplesINeed","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2025-09-04 UTC."],[],[],null,["# Class CollectionGroup (7.11.0)\n\nVersion latestkeyboard_arrow_down\n\n- [7.11.0 (latest)](/nodejs/docs/reference/firestore/latest/firestore/collectiongroup)\n- [7.9.0](/nodejs/docs/reference/firestore/7.9.0/firestore/collectiongroup)\n- [7.7.0](/nodejs/docs/reference/firestore/7.7.0/firestore/collectiongroup)\n- [7.6.0](/nodejs/docs/reference/firestore/7.6.0/firestore/collectiongroup)\n- [7.5.0](/nodejs/docs/reference/firestore/7.5.0/firestore/collectiongroup)\n- [7.4.0](/nodejs/docs/reference/firestore/7.4.0/firestore/collectiongroup)\n- [7.3.1](/nodejs/docs/reference/firestore/7.3.1/firestore/collectiongroup)\n- [7.2.0](/nodejs/docs/reference/firestore/7.2.0/firestore/collectiongroup)\n- [7.1.0](/nodejs/docs/reference/firestore/7.1.0/firestore/collectiongroup)\n- [6.4.1](/nodejs/docs/reference/firestore/6.4.1/firestore/collectiongroup)\n- [6.3.0](/nodejs/docs/reference/firestore/6.3.0/firestore/collectiongroup)\n- [6.0.0](/nodejs/docs/reference/firestore/6.0.0/firestore/collectiongroup)\n- [5.0.2](/nodejs/docs/reference/firestore/5.0.2/firestore/collectiongroup)\n- [4.15.1](/nodejs/docs/reference/firestore/4.15.1/firestore/collectiongroup)\n- [4.14.2](/nodejs/docs/reference/firestore/4.14.2/firestore/collectiongroup)\n- [4.9.8](/nodejs/docs/reference/firestore/4.9.8/firestore/collectiongroup) \nA `CollectionGroup` refers to all documents that are contained in a collection or subcollection with a specific collection ID.\n\nCollectionGroup \n\nInheritance\n-----------\n\n[Query](/nodejs/docs/reference/firestore/latest/firestore/query)\\\u003cAppModelType, DbModelType\\\u003e \\\u003e CollectionGroup\n\nPackage\n-------\n\n[@google-cloud/firestore](../overview.html)\n\nConstructors\n------------\n\n### (constructor)(firestore, collectionId, converter)\n\n constructor(firestore: Firestore, collectionId: string, converter: firestore.FirestoreDataConverter\u003cAppModelType, DbModelType\u003e | undefined);\n\nConstructs a new instance of the `CollectionGroup` class\n\nMethods\n-------\n\n### getPartitions(desiredPartitionCount)\n\n getPartitions(desiredPartitionCount: number): AsyncIterable\u003cQueryPartition\u003cAppModelType, DbModelType\u003e\u003e;\n\nPartitions a query by returning partition cursors that can be used to run the query in parallel. The returned cursors are split points that can be used as starting and end points for individual query invocations.\n\n**Example** \n\n\n const query = firestore.collectionGroup('collectionId');\n for await (const partition of query.getPartitions(42)) {\n const partitionedQuery = partition.toQuery();\n const querySnapshot = await partitionedQuery.get();\n console.log(`Partition contained ${querySnapshot.length} documents`);\n }\n\n### withConverter(converter)\n\n withConverter(converter: null): CollectionGroup;\n\nApplies a custom data converter to this `CollectionGroup`, allowing you to use your own custom model objects with Firestore. When you call get() on the returned `CollectionGroup`, the provided converter will convert between Firestore data of type `NewDbModelType` and your custom type `NewAppModelType`.\n\nUsing the converter allows you to specify generic type arguments when storing and retrieving objects from Firestore.\n\nPassing in `null` as the converter parameter removes the current converter.\n\n**Example** \n\n\n class Post {\n constructor(readonly title: string, readonly author: string) {}\n\n toString(): string {\n return this.title + ', by ' + this.author;\n }\n }\n\n const postConverter = {\n toFirestore(post: Post): FirebaseFirestore.DocumentData {\n return {title: post.title, author: post.author};\n },\n fromFirestore(\n snapshot: FirebaseFirestore.QueryDocumentSnapshot\n ): Post {\n const data = snapshot.data();\n return new Post(data.title, data.author);\n }\n };\n\n const querySnapshot = await Firestore()\n .collectionGroup('posts')\n .withConverter(postConverter)\n .get();\n for (const doc of querySnapshot.docs) {\n const post = doc.data();\n post.title; // string\n post.toString(); // Should be defined\n post.someNonExistentProperty; // TS error\n }\n\n### withConverter(converter)\n\n withConverter\u003cNewAppModelType, NewDbModelType extends firestore.DocumentData = firestore.DocumentData\u003e(converter: firestore.FirestoreDataConverter\u003cNewAppModelType, NewDbModelType\u003e): CollectionGroup\u003cNewAppModelType, NewDbModelType\u003e;"]]