Cloud Firestore API - Class Google::Cloud::Firestore::AggregateQuerySnapshot (v2.8.0)

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

AggregateQuerySnapshot

An aggregate query snapshot object is an immutable representation for an aggregate query result.

Inherits

  • Object

Example

require "google/cloud/firestore"

firestore = Google::Cloud::Firestore.new

query = firestore.col "cities"

# Create an aggregate query
aggregate_query = query.aggregate_query
                       .add_count

aggregate_query.get do |aggregate_snapshot|
  puts aggregate_snapshot.get('count')
end

Methods

#get

def get(aggregate_alias) -> Integer

Retrieves the aggregate data.

Parameter
  • aggregate_alias (String) — The alias used to access the aggregate value. For count, the default value is "count".
Returns
  • (Integer) — The aggregate value.
Example
require "google/cloud/firestore"

firestore = Google::Cloud::Firestore.new

query = firestore.col "cities"

# Create an aggregate query
aggregate_query = query.aggregate_query
                       .add_count

aggregate_query.get do |aggregate_snapshot|
  puts aggregate_snapshot.get('count')
end