Cloud Firestore API - Class Google::Cloud::Firestore::CollectionGroup (v2.9.0)

Reference documentation and code samples for the Cloud Firestore API class Google::Cloud::Firestore::CollectionGroup.

CollectionGroup

A collection group object is used for adding documents, getting document references, and querying for documents, including with partitions.

See Google::Cloud::Firestore::Client#col_group and Query.

Example

require "google/cloud/firestore"

firestore = Google::Cloud::Firestore.new

# Get a collection group
col_group = firestore.col_group "cities"

# Get and print all city documents
col_group.get do |city|
  puts "#{city.document_id} has #{city[:population]} residents."
end

Methods

#partitions

def partitions(partition_count, read_time: nil) -> Array<QueryPartition>

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
Raises
  • (ArgumentError)
Examples
require "google/cloud/firestore"

firestore = Google::Cloud::Firestore.new

col_group = firestore.col_group "cities"

partitions = col_group.partitions 3

queries = partitions.map(&:to_query)

partition with read time

require "google/cloud/firestore"

firestore = Google::Cloud::Firestore.new

col_group = firestore.col_group "cities"

read_time = Time.now

partitions = col_group.partitions 3, read_time: read_time

queries = partitions.map(&:to_query)