Class: Google::Cloud::Firestore::AggregateQuerySnapshot

Inherits:
Object
  • Object
show all
Defined in:
lib/google/cloud/firestore/aggregate_query_snapshot.rb

Overview

AggregateQuerySnapshot

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

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('count')
end

Instance Method Summary collapse

Instance Method Details

#get(aggregate_alias) ⇒ Integer

Retrieves the aggregate data.

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('count')
end

Parameters:

  • aggregate_alias (String)

    The alias used to access the aggregate value. For count, the default value is "count".

Returns:

  • (Integer)

    The aggregate value.



64
65
66
# File 'lib/google/cloud/firestore/aggregate_query_snapshot.rb', line 64

def get aggregate_alias
  @aggregate_fields[aggregate_alias]
end