require"google/cloud/firestore"firestore=Google::Cloud::Firestore.new# Get a collection groupcol_group=firestore.col_group"cities"# Get and print all city documentscol_group.getdo|city|puts"#{city.document_id} has #{city[:population]} residents."end
Partitions a query by returning partition cursors that can be used to run the query in parallel. The returned
partition cursors are split points that can be used as starting/end points for the query results.
Parameters
partition_count (Integer) — The desired maximum number of partition points. The number must be strictly
positive. The actual number of partitions returned may be fewer.
read_time (Time) (defaults to: nil) — Reads documents as they were at the given time.
This may not be older than 270 seconds. Optional
Returns
(Array<QueryPartition>) — An ordered array of query partitions.
[[["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-09 UTC."],[],[],null,["# Cloud Firestore API - Class Google::Cloud::Firestore::CollectionGroup (v3.1.0)\n\nVersion latestkeyboard_arrow_down\n\n- [3.1.0 (latest)](/ruby/docs/reference/google-cloud-firestore/latest/Google-Cloud-Firestore-CollectionGroup)\n- [3.0.0](/ruby/docs/reference/google-cloud-firestore/3.0.0/Google-Cloud-Firestore-CollectionGroup)\n- [2.16.1](/ruby/docs/reference/google-cloud-firestore/2.16.1/Google-Cloud-Firestore-CollectionGroup)\n- [2.15.1](/ruby/docs/reference/google-cloud-firestore/2.15.1/Google-Cloud-Firestore-CollectionGroup)\n- [2.14.0](/ruby/docs/reference/google-cloud-firestore/2.14.0/Google-Cloud-Firestore-CollectionGroup)\n- [2.13.1](/ruby/docs/reference/google-cloud-firestore/2.13.1/Google-Cloud-Firestore-CollectionGroup)\n- [2.12.0](/ruby/docs/reference/google-cloud-firestore/2.12.0/Google-Cloud-Firestore-CollectionGroup)\n- [2.11.0](/ruby/docs/reference/google-cloud-firestore/2.11.0/Google-Cloud-Firestore-CollectionGroup)\n- [2.10.1](/ruby/docs/reference/google-cloud-firestore/2.10.1/Google-Cloud-Firestore-CollectionGroup)\n- [2.9.1](/ruby/docs/reference/google-cloud-firestore/2.9.1/Google-Cloud-Firestore-CollectionGroup)\n- [2.8.0](/ruby/docs/reference/google-cloud-firestore/2.8.0/Google-Cloud-Firestore-CollectionGroup)\n- [2.7.2](/ruby/docs/reference/google-cloud-firestore/2.7.2/Google-Cloud-Firestore-CollectionGroup)\n- [2.6.6](/ruby/docs/reference/google-cloud-firestore/2.6.6/Google-Cloud-Firestore-CollectionGroup) \nReference documentation and code samples for the Cloud Firestore API class Google::Cloud::Firestore::CollectionGroup.\n\nCollectionGroup\n---------------\n\nA collection group object is used for adding documents, getting\ndocument references, and querying for documents, including with partitions.\n\nSee [Google::Cloud::Firestore::Client#col_group](/ruby/docs/reference/google-cloud-firestore/latest/Google-Cloud-Firestore-Client#Google__Cloud__Firestore__Client_col_group_instance_ \"Google::Cloud::Firestore::Client#col_group (method)\") and [Query](/ruby/docs/reference/google-cloud-firestore/latest/Google-Cloud-Firestore-Query \"Google::Cloud::Firestore::Query (class)\"). \n\nInherits\n--------\n\n- [Google::Cloud::Firestore::Query](./Google-Cloud-Firestore-Query)\n\nExample\n-------\n\n```ruby\nrequire \"google/cloud/firestore\"\n\nfirestore = Google::Cloud::Firestore.new\n\n# Get a collection group\ncol_group = firestore.col_group \"cities\"\n\n# Get and print all city documents\ncol_group.get do |city|\n puts \"#{city.document_id} has #{city[:population]} residents.\"\nend\n```\n\nMethods\n-------\n\n### #partitions\n\n def partitions(partition_count, read_time: nil) -\u003e Array\u003cQueryPartition\u003e\n\nPartitions a query by returning partition cursors that can be used to run the query in parallel. The returned\npartition cursors are split points that can be used as starting/end points for the query results. \n**Parameters**\n\n- **partition_count** (Integer) --- The desired maximum number of partition points. The number must be strictly positive. The actual number of partitions returned may be fewer.\n- **read_time** (Time) *(defaults to: nil)* --- Reads documents as they were at the given time. This may not be older than 270 seconds. Optional \n**Returns**\n\n- (Array\\\u003c[QueryPartition](./Google-Cloud-Firestore-QueryPartition)\\\u003e) --- An ordered array of query partitions. \n**Raises**\n\n- (ArgumentError)\n**Examples** \n\n```ruby\nrequire \"google/cloud/firestore\"\n\nfirestore = Google::Cloud::Firestore.new\n\ncol_group = firestore.col_group \"cities\"\n\npartitions = col_group.partitions 3\n\nqueries = partitions.map(&:to_query)\n```\n\npartition with read time \n\n```ruby\nrequire \"google/cloud/firestore\"\n\nfirestore = Google::Cloud::Firestore.new\n\ncol_group = firestore.col_group \"cities\"\n\nread_time = Time.now\n\npartitions = col_group.partitions 3, read_time: read_time\n\nqueries = partitions.map(&:to_query)\n```"]]