Aggregation

Classes for representing aggregation queries for the Google Cloud Firestore API.

A AggregationQuery can be created directly from a Collection and that can be a more common way to create an aggregation query than direct usage of the constructor.

class google.cloud.firestore_v1.aggregation.AggregationQuery(nested_query)

Bases: google.cloud.firestore_v1.base_aggregation.BaseAggregationQuery

Represents an aggregation query to the Firestore API.

get(transaction=None, retry: Union[retries.Retry, None, gapic_v1.method._MethodDefault] = <_MethodDefault._DEFAULT_VALUE:

Runs the aggregation query.

This sends a RunAggregationQuery RPC and returns a list of aggregation results in the stream of RunAggregationQueryResponse messages.

  • Parameters

    • transaction – (Optional[Transaction]): An existing transaction that this query will run in. If a transaction is used and it already has write operations added, this method cannot be used (i.e. read-after-write is not allowed).

    • 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

    The aggregation query results

  • Return type

    list

stream(transaction=None, retry: Union[retries.Retry, None, gapic_v1.method._MethodDefault] = <_MethodDefault._DEFAULT_VALUE:

Runs the aggregation query.

This sends a RunAggregationQuery RPC and then returns an iterator which consumes each document returned in the stream of RunAggregationQueryResponse messages.

If a transaction is used and it already has write operations added, this method cannot be used (i.e. read-after-write is not allowed).

  • Parameters

    • transaction – (Optional[Transaction]): An existing transaction that this query will run in.

    • 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.

  • Yields

    AggregationResult – The result of aggregations of this query

Classes for representing aggregation queries for the Google Cloud Firestore API.

A AggregationQuery can be created directly from a Collection and that can be a more common way to create an aggregation query than direct usage of the constructor.

class google.cloud.firestore_v1.base_aggregation.AggregationResult(alias: str, value: int, read_time=None)

Bases: object

A class representing result from Aggregation Query :type alias: str :param alias: The alias for the aggregation. :type value: int :param value: The resulting value from the aggregation. :type read_time: :param value: The resulting read_time

class google.cloud.firestore_v1.base_aggregation.BaseAggregation()

Bases: abc.ABC

class google.cloud.firestore_v1.base_aggregation.BaseAggregationQuery(nested_query)

Bases: abc.ABC

Represents an aggregation query to the Firestore API.

add_aggregation(aggregation: google.cloud.firestore_v1.base_aggregation.BaseAggregation)

Adds an aggregation operation to the nested query

  • Parameters

    aggregation (google.cloud.firestore_v1.aggregation.BaseAggregation) – An aggregation operation, e.g. a CountAggregation

add_aggregations(aggregations: List[google.cloud.firestore_v1.base_aggregation.BaseAggregation])

Adds a list of aggregations to the nested query

  • Parameters

    aggregations (list) – a list of aggregation operations

count(alias: str | None = None)

Adds a count over the nested query

abstract get(transaction=None, retry: Union[retries.Retry, None, gapic_v1.method._MethodDefault] = <_MethodDefault._DEFAULT_VALUE:

Runs the aggregation query.

This sends a RunAggregationQuery RPC and returns a list of aggregation results in the stream of RunAggregationQueryResponse messages.

  • Parameters

    • transaction – (Optional[Transaction]): An existing transaction that this query will run in. If a transaction is used and it already has write operations added, this method cannot be used (i.e. read-after-write is not allowed).

    • 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

    The aggregation query results

  • Return type

    list

abstract stream(transaction=None, retry: Union[retries.Retry, None, gapic_v1.method._MethodDefault] = <_MethodDefault._DEFAULT_VALUE:

Runs the aggregation query.

This sends a``RunAggregationQuery`` RPC and returns an iterator in the stream of RunAggregationQueryResponse messages.

  • Parameters

    • transaction – (Optional[Transaction]): An existing transaction that this query will run in. If a transaction is used and it already has write operations added, this method cannot be used (i.e. read-after-write is not allowed).

    • 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

    The aggregation query results

  • Return type

    list

class google.cloud.firestore_v1.base_aggregation.CountAggregation(alias: str | None = None)

Bases: google.cloud.firestore_v1.base_aggregation.BaseAggregation

Classes for representing Async aggregation queries for the Google Cloud Firestore API.

A AsyncAggregationQuery can be created directly from a AsyncCollection and that can be a more common way to create an aggregation query than direct usage of the constructor.

class google.cloud.firestore_v1.async_aggregation.AsyncAggregationQuery(nested_query)

Bases: google.cloud.firestore_v1.base_aggregation.BaseAggregationQuery

Represents an aggregation query to the Firestore API.

async get(transaction=None, retry: Union[retries.Retry, None, gapic_v1.method._MethodDefault] = <_MethodDefault._DEFAULT_VALUE:

Runs the aggregation query.

This sends a RunAggregationQuery RPC and returns a list of aggregation results in the stream of RunAggregationQueryResponse messages.

  • Parameters

    • transaction – (Optional[Transaction]): An existing transaction that this query will run in. If a transaction is used and it already has write operations added, this method cannot be used (i.e. read-after-write is not allowed).

    • 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

    The aggregation query results

  • Return type

    list

stream(transaction=None, retry: Union[retries.Retry, None, gapic_v1.method._MethodDefault] = <_MethodDefault._DEFAULT_VALUE:

Runs the aggregation query.

This sends a RunAggregationQuery RPC and then returns an iterator which consumes each document returned in the stream of RunAggregationQueryResponse messages.

If a transaction is used and it already has write operations added, this method cannot be used (i.e. read-after-write is not allowed).

  • Parameters

    • transaction – (Optional[Transaction]): An existing transaction that this query will run in.

    • 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.

  • Yields

    AggregationResult – The result of aggregations of this query