Query a collection group using a partitioned query

Stay organized with collections Save and categorize content based on your preferences.

Query a collection group using a partitioned query

Code sample


cities := client.CollectionGroup("cities")

// Get a partioned query for the cities collection group, with a maximum
// partition count of 10
partitionedQueries, err := cities.GetPartitionedQueries(ctx, 10)
if err != nil {
	return fmt.Errorf("GetPartitionedQueries: %v", err)

fmt.Printf("Collection Group query partitioned to %d queries\n", len(partitionedQueries))

// Retrieve the first query and iterate over the documents contained.
query := partitionedQueries[0]
iter := query.Documents(ctx)
for {
	doc, err := iter.Next()
	if err == iterator.Done {
	if err != nil {
		return fmt.Errorf("documents iterator: %v", err)

What's next

To search and filter code samples for other Google Cloud products, see the Google Cloud sample browser.