The result of the aggregation query, returned as a hash of key-value
pairs. The key is the alias of the aggregate function, and the value
is the result of the aggregation.
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, Float, nil) — The aggregate value. Returns nil
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Hard to understand","hardToUnderstand","thumb-down"],["Incorrect information or sample code","incorrectInformationOrSampleCode","thumb-down"],["Missing the information/samples I need","missingTheInformationSamplesINeed","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2025-08-28 UTC."],[],[],null,["# Firestore in Datastore mode API - Class Google::Cloud::Datastore::Dataset::AggregateQueryResults (v2.13.0)\n\nVersion latestkeyboard_arrow_down\n\n- [2.13.0 (latest)](/ruby/docs/reference/google-cloud-datastore/latest/Google-Cloud-Datastore-Dataset-AggregateQueryResults)\n- [2.12.0](/ruby/docs/reference/google-cloud-datastore/2.12.0/Google-Cloud-Datastore-Dataset-AggregateQueryResults)\n- [2.11.0](/ruby/docs/reference/google-cloud-datastore/2.11.0/Google-Cloud-Datastore-Dataset-AggregateQueryResults)\n- [2.10.0](/ruby/docs/reference/google-cloud-datastore/2.10.0/Google-Cloud-Datastore-Dataset-AggregateQueryResults)\n- [2.9.0](/ruby/docs/reference/google-cloud-datastore/2.9.0/Google-Cloud-Datastore-Dataset-AggregateQueryResults)\n- [2.8.0](/ruby/docs/reference/google-cloud-datastore/2.8.0/Google-Cloud-Datastore-Dataset-AggregateQueryResults)\n- [2.7.1](/ruby/docs/reference/google-cloud-datastore/2.7.1/Google-Cloud-Datastore-Dataset-AggregateQueryResults)\n- [2.6.0](/ruby/docs/reference/google-cloud-datastore/2.6.0/Google-Cloud-Datastore-Dataset-AggregateQueryResults)\n- [2.5.0](/ruby/docs/reference/google-cloud-datastore/2.5.0/Google-Cloud-Datastore-Dataset-AggregateQueryResults)\n- [2.4.0](/ruby/docs/reference/google-cloud-datastore/2.4.0/Google-Cloud-Datastore-Dataset-AggregateQueryResults)\n- [2.3.1](/ruby/docs/reference/google-cloud-datastore/2.3.1/Google-Cloud-Datastore-Dataset-AggregateQueryResults)\n- [2.2.4](/ruby/docs/reference/google-cloud-datastore/2.2.4/Google-Cloud-Datastore-Dataset-AggregateQueryResults) \nReference documentation and code samples for the Firestore in Datastore mode API class Google::Cloud::Datastore::Dataset::AggregateQueryResults.\n\nAggregateQueryResults\n---------------------\n\nAn AggregateQueryResult object is a representation for\na result of an AggregateQuery or a GqlQuery. \n\nInherits\n--------\n\n- Object\n\nExample\n-------\n\n```ruby\nrequire \"google/cloud/datastore\"\n\ndatastore = Google::Cloud::Datastore.new\n\nquery = Google::Cloud::Datastore::Query.new\nquery.kind(\"Task\")\n .where(\"done\", \"=\", false)\n\nCreate an aggregate query\naggregate_query = query.aggregate_query\n .add_count\n\naggregate_query_results = dataset.run_aggregation aggregate_query\nputs aggregate_query_results.get\n```\n\nMethods\n-------\n\n### #aggregate_fields\n\n def aggregate_fields() -\u003e Hash{String =\u003e Integer, Float}\n\nThe result of the aggregation query, returned as a hash of key-value\npairs. The key is the alias of the aggregate function, and the value\nis the result of the aggregation.\n\nThe alias of the aggregate function can be:\n\n- an aggregate literal \"sum\", \"avg\", or \"count\"\n- a custom aggregate alias \n**Returns**\n\n- (Hash{String =\\\u003e Integer, Float})\n\n### #explain_metrics\n\n def explain_metrics() -\u003e Google::Cloud::Datastore::V1::ExplainMetrics, nil\n\nQuery explain metrics. This is only present when the `explain_options`\nare provided to [#run_aggregation](/ruby/docs/reference/google-cloud-datastore/latest/Google-Cloud-Datastore-Dataset#Google__Cloud__Datastore__Dataset_run_aggregation_instance_ \"Google::Cloud::Datastore::Dataset#run_aggregation (method)\").\nIt is sent only once with the response. \n**Returns**\n\n- (Google::Cloud::Datastore::V1::ExplainMetrics, nil)\n\n### #explain_options\n\n def explain_options() -\u003e Google::Cloud::Datastore::V1::ExplainOptions, nil\n\nThe options for query explanation.\n\n\n\u003cbr /\u003e\n\nThis is a copy of the input parameter supplied to the [#run_aggregation](/ruby/docs/reference/google-cloud-datastore/latest/Google-Cloud-Datastore-Dataset#Google__Cloud__Datastore__Dataset_run_aggregation_instance_ \"Google::Cloud::Datastore::Dataset#run_aggregation (method)\") function. \n**Returns**\n\n- (Google::Cloud::Datastore::V1::ExplainOptions, nil)\n\n### #get\n\n def get(aggregate_alias = nil) -\u003e Integer, Float, nil\n\nRetrieves the aggregate data.\n\n\n\u003cbr /\u003e\n\nif the aggregate_alias does not exist. \n**Parameter**\n\n- **aggregate_alias** (String) --- The alias used to access the aggregate value. For an AggregateQuery with a single aggregate field, this parameter can be omitted. \n**Returns**\n\n- (Integer, Float, nil) --- The aggregate value. Returns `nil`\n**Examples** \n\n```ruby\nrequire \"google/cloud/datastore\"\n\ndatastore = Google::Cloud::Datastore.new\n\nquery = Google::Cloud::Datastore::Query.new\nquery.kind(\"Task\")\n .where(\"done\", \"=\", false)\n\nCreate an aggregate query\naggregate_query = query.aggregate_query\n .add_count\n\naggregate_query_results = dataset.run_aggregation aggregate_query\nputs aggregate_query_results.get\n```\n\nAlias an aggregate query \n\n```ruby\nrequire \"google/cloud/datastore\"\n\ndatastore = Google::Cloud::Datastore.new\n\nquery = Google::Cloud::Datastore::Query.new\nquery.kind(\"Task\")\n .where(\"done\", \"=\", false)\n\nCreate an aggregate query\naggregate_query = query.aggregate_query\n .add_count aggregate_alias: 'total'\n\naggregate_query_results = dataset.run_aggregation aggregate_query\nputs aggregate_query_results.get('total')\n```\n\n### #read_time\n\n def read_time() -\u003e Google::Protobuf::Timestamp\n\nThe time when the query was executed. \n**Returns**\n\n- (Google::Protobuf::Timestamp)"]]