Class BaseAggregationQuery (2.21.0)
Stay organized with collections
Save and categorize content based on your preferences.
BaseAggregationQuery(nested_query, alias: typing.Optional[str] = None)
Represents an aggregation query to the Firestore API.
Methods
add_aggregation
add_aggregation(
aggregation: google.cloud.firestore_v1.base_aggregation.BaseAggregation,
) -> None
Adds an aggregation operation to the nested query
Parameter |
Name |
Description |
aggregation |
BaseAggregation
An aggregation operation, e.g. a CountAggregation
|
add_aggregations
add_aggregations(
aggregations: typing.List[
google.cloud.firestore_v1.base_aggregation.BaseAggregation
],
) -> None
Adds a list of aggregations to the nested query
Parameter |
Name |
Description |
aggregations |
list
a list of aggregation operations
|
avg
avg(
field_ref: str | google.cloud.firestore_v1.field_path.FieldPath,
alias: typing.Optional[str] = None,
)
Adds an avg over the nested query
count
count(alias: typing.Optional[str] = None)
Adds a count over the nested query
get
get(
transaction=None,
retry: Union[
retries.Retry, retries.AsyncRetry, None, object
] = _MethodDefault._DEFAULT_VALUE,
timeout: float | None = None,
*,
explain_options: Optional[ExplainOptions] = None
) -> (
QueryResultsList[AggregationResult]
| Coroutine[Any, Any, List[List[AggregationResult]]]
)
Runs the aggregation query.
This sends a RunAggregationQuery
RPC and returns a list of
aggregation results in the stream of RunAggregationQueryResponse
messages.
Parameters |
Name |
Description |
retry |
google.api_core.retry.Retry
Designation of what errors, if any, should be retried. Defaults to a system-specified policy.
|
timeout |
float
The timeout for this request. Defaults to a system-specified value.
|
Returns |
Type |
Description |
(QueryResultsList[List[AggregationResult]] Coroutine[Any, Any, List[List[AggregationResult]]]) |
The aggregation query results. |
stream
stream(
transaction: Optional[transaction.Transaction] = None,
retry: (
retries.Retry | retries.AsyncRetry | object | None
) = _MethodDefault._DEFAULT_VALUE,
timeout: Optional[float] = None,
*,
explain_options: Optional[ExplainOptions] = None
) -> (
StreamGenerator[List[AggregationResult]]
| AsyncStreamGenerator[List[AggregationResult]]
)
Runs the aggregation query.
This sends aRunAggregationQuery
RPC and returns a generator in the stream of RunAggregationQueryResponse
messages.
Parameters |
Name |
Description |
retry |
Optional[google.api_core.retry.Retry]
Designation of what errors, if any, should be retried. Defaults to a system-specified policy.
|
timeout |
Optinal[float]
The timeout for this request. Defaults to a system-specified value.
|
Returns |
Type |
Description |
StreamGenerator[List[AggregationResult]] AsyncStreamGenerator[List[AggregationResult]] |
A generator of the query results. |
sum
sum(
field_ref: str | google.cloud.firestore_v1.field_path.FieldPath,
alias: typing.Optional[str] = None,
)
Adds a sum over the nested query
Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License, and code samples are licensed under the Apache 2.0 License. For details, see the Google Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.
Last updated 2025-08-28 UTC.
[[["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,["# Class BaseAggregationQuery (2.21.0)\n\nVersion latestkeyboard_arrow_down\n\n- [2.21.0 (latest)](/python/docs/reference/firestore/latest/google.cloud.firestore_v1.base_aggregation.BaseAggregationQuery)\n- [2.20.2](/python/docs/reference/firestore/2.20.2/google.cloud.firestore_v1.base_aggregation.BaseAggregationQuery)\n- [2.19.0](/python/docs/reference/firestore/2.19.0/google.cloud.firestore_v1.base_aggregation.BaseAggregationQuery)\n- [2.18.0](/python/docs/reference/firestore/2.18.0/google.cloud.firestore_v1.base_aggregation.BaseAggregationQuery)\n- [2.17.2](/python/docs/reference/firestore/2.17.2/google.cloud.firestore_v1.base_aggregation.BaseAggregationQuery)\n- [2.16.1](/python/docs/reference/firestore/2.16.1/google.cloud.firestore_v1.base_aggregation.BaseAggregationQuery)\n- [2.15.0](/python/docs/reference/firestore/2.15.0/google.cloud.firestore_v1.base_aggregation.BaseAggregationQuery)\n- [2.14.0](/python/docs/reference/firestore/2.14.0/google.cloud.firestore_v1.base_aggregation.BaseAggregationQuery)\n- [2.13.1](/python/docs/reference/firestore/2.13.1/google.cloud.firestore_v1.base_aggregation.BaseAggregationQuery)\n- [2.12.0](/python/docs/reference/firestore/2.12.0/google.cloud.firestore_v1.base_aggregation.BaseAggregationQuery)\n- [2.11.1](/python/docs/reference/firestore/2.11.1/google.cloud.firestore_v1.base_aggregation.BaseAggregationQuery)\n- [2.10.1](/python/docs/reference/firestore/2.10.1/google.cloud.firestore_v1.base_aggregation.BaseAggregationQuery)\n- [2.9.1](/python/docs/reference/firestore/2.9.1/google.cloud.firestore_v1.base_aggregation.BaseAggregationQuery)\n- [2.8.0](/python/docs/reference/firestore/2.8.0/google.cloud.firestore_v1.base_aggregation.BaseAggregationQuery)\n- [2.7.3](/python/docs/reference/firestore/2.7.3/google.cloud.firestore_v1.base_aggregation.BaseAggregationQuery)\n- [2.6.1](/python/docs/reference/firestore/2.6.1/google.cloud.firestore_v1.base_aggregation.BaseAggregationQuery)\n- [2.5.3](/python/docs/reference/firestore/2.5.3/google.cloud.firestore_v1.base_aggregation.BaseAggregationQuery)\n- [2.4.0](/python/docs/reference/firestore/2.4.0/google.cloud.firestore_v1.base_aggregation.BaseAggregationQuery)\n- [2.3.4](/python/docs/reference/firestore/2.3.4/google.cloud.firestore_v1.base_aggregation.BaseAggregationQuery)\n- [2.2.0](/python/docs/reference/firestore/2.2.0/google.cloud.firestore_v1.base_aggregation.BaseAggregationQuery)\n- [2.1.3](/python/docs/reference/firestore/2.1.3/google.cloud.firestore_v1.base_aggregation.BaseAggregationQuery)\n- [2.0.2](/python/docs/reference/firestore/2.0.2/google.cloud.firestore_v1.base_aggregation.BaseAggregationQuery)\n- [1.9.2](/python/docs/reference/firestore/1.9.2/google.cloud.firestore_v1.base_aggregation.BaseAggregationQuery)\n- [1.8.1](/python/docs/reference/firestore/1.8.1/google.cloud.firestore_v1.base_aggregation.BaseAggregationQuery)\n- [1.7.0](/python/docs/reference/firestore/1.7.0/google.cloud.firestore_v1.base_aggregation.BaseAggregationQuery)\n- [1.6.2](/python/docs/reference/firestore/1.6.2/google.cloud.firestore_v1.base_aggregation.BaseAggregationQuery)\n- [1.5.0](/python/docs/reference/firestore/1.5.0/google.cloud.firestore_v1.base_aggregation.BaseAggregationQuery)\n- [1.4.0](/python/docs/reference/firestore/1.4.0/google.cloud.firestore_v1.base_aggregation.BaseAggregationQuery)\n- [1.3.0](/python/docs/reference/firestore/1.3.0/google.cloud.firestore_v1.base_aggregation.BaseAggregationQuery) \n\n BaseAggregationQuery(nested_query, alias: typing.Optional[str] = None)\n\nRepresents an aggregation query to the Firestore API.\n\nMethods\n-------\n\n### add_aggregation\n\n add_aggregation(\n aggregation: google.cloud.firestore_v1.base_aggregation.BaseAggregation,\n ) -\u003e None\n\nAdds an aggregation operation to the nested query\n\n### add_aggregations\n\n add_aggregations(\n aggregations: typing.List[\n google.cloud.firestore_v1.base_aggregation.BaseAggregation\n ],\n ) -\u003e None\n\nAdds a list of aggregations to the nested query\n\n### avg\n\n avg(\n field_ref: str | google.cloud.firestore_v1.field_path.FieldPath,\n alias: typing.Optional[str] = None,\n )\n\nAdds an avg over the nested query\n\n### count\n\n count(alias: typing.Optional[str] = None)\n\nAdds a count over the nested query\n\n### get\n\n get(\n transaction=None,\n retry: Union[\n retries.Retry, retries.AsyncRetry, None, object\n ] = _MethodDefault._DEFAULT_VALUE,\n timeout: float | None = None,\n *,\n explain_options: Optional[ExplainOptions] = None\n ) -\u003e (\n QueryResultsList[AggregationResult]\n | Coroutine[Any, Any, List[List[AggregationResult]]]\n )\n\nRuns the aggregation query.\n\nThis sends a `RunAggregationQuery` RPC and returns a list of\naggregation results in the stream of `RunAggregationQueryResponse`\nmessages.\n\n### stream\n\n stream(\n transaction: Optional[transaction.Transaction] = None,\n retry: (\n retries.Retry | retries.AsyncRetry | object | None\n ) = _MethodDefault._DEFAULT_VALUE,\n timeout: Optional[float] = None,\n *,\n explain_options: Optional[ExplainOptions] = None\n ) -\u003e (\n StreamGenerator[List[AggregationResult]]\n | AsyncStreamGenerator[List[AggregationResult]]\n )\n\nRuns the aggregation query.\n\nThis sends a`RunAggregationQuery` RPC and returns a generator in the stream of `RunAggregationQueryResponse` messages.\n\n### sum\n\n sum(\n field_ref: str | google.cloud.firestore_v1.field_path.FieldPath,\n alias: typing.Optional[str] = None,\n )\n\nAdds a sum over the nested query"]]