Cloud Firestore API - Class Google::Cloud::Firestore::AggregateQuerySnapshot (v2.10.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

Examples

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
end

Alias an aggregate query

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_alias: 'total'

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

Methods

#get

def get(aggregate_alias = nil) -> Integer

Retrieves the aggregate data.

Parameter
  • aggregate_alias (String) — The alias used to access the aggregate value. For an AggregateQuery with a single aggregate field, this parameter can be omitted.
Returns
  • (Integer) — The aggregate value.
  • (Integer) — The aggregate value.
Examples
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
end

Alias an aggregate query

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_alias: 'total'

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