# Cloud Firestore V1 Client - Class Aggregation (2.2.0-RC1)

2.2.0-RC1 2.1.0 (latest) 2.0.2-RC1 1.55.0 1.54.4 1.53.1 1.52.0 1.51.0 1.50.0 1.48.1 1.47.3 1.46.0 1.45.2 1.44.1 1.43.3 1.40.0 1.39.0 1.38.0 1.37.7 1.36.1 1.35.0 1.34.0 1.33.0 1.32.0 1.31.0 1.30.0 1.28.0 1.27.3 Reference documentation and code samples for the Cloud Firestore V1 Client class Aggregation.

Defines an aggregation that produces a single result.

Generated from protobuf message `google.firestore.v1.StructuredAggregationQuery.Aggregation`

## Namespace

Google \\ Cloud \\ Firestore \\ V1 \\ StructuredAggregationQuery

## Methods

### __construct

Constructor.

| **Parameters** ||
|---|---|
| **Name** | **Description** |
| `data` | `array` Optional. Data for populating the Message object. |
| `↳ count` | `https://docs.cloud.google.com/php/docs/reference/cloud-firestore/latest/V1.StructuredAggregationQuery.Aggregation.Count` Count aggregator. |
| `↳ sum` | `https://docs.cloud.google.com/php/docs/reference/cloud-firestore/latest/V1.StructuredAggregationQuery.Aggregation.Sum` Sum aggregator. |
| `↳ avg` | `https://docs.cloud.google.com/php/docs/reference/cloud-firestore/latest/V1.StructuredAggregationQuery.Aggregation.Avg` Average aggregator. |
| `↳ alias` | `string` Optional. Optional name of the field to store the result of the aggregation into. If not provided, Firestore will pick a default name following the format `field_<incremental_id++>`. For example: `AGGREGATE COUNT_UP_TO(1) AS count_up_to_1, COUNT_UP_TO(2), COUNT_UP_TO(3) AS count_up_to_3, COUNT(*) OVER ( ... );` becomes: `AGGREGATE COUNT_UP_TO(1) AS count_up_to_1, COUNT_UP_TO(2) AS field_1, COUNT_UP_TO(3) AS count_up_to_3, COUNT(*) AS field_2 OVER ( ... );` Requires: \* \* Must be unique across all aggregation aliases. \* \* Conform to [document field name](https://docs.cloud.google.com/php/docs/reference/cloud-firestore/latest/V1.Document#_Google_Cloud_Firestore_V1_Document__getFields__) limitations. |

### getCount

Count aggregator.

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.cloud.google.com/php/docs/reference/cloud-firestore/latest/V1.StructuredAggregationQuery.Aggregation.Count|null` |   |

### hasCount

### setCount

Count aggregator.

| **Parameter** ||
|---|---|
| **Name** | **Description** |
| `var` | `https://docs.cloud.google.com/php/docs/reference/cloud-firestore/latest/V1.StructuredAggregationQuery.Aggregation.Count` |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `$this` |   |

### getSum

Sum aggregator.

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.cloud.google.com/php/docs/reference/cloud-firestore/latest/V1.StructuredAggregationQuery.Aggregation.Sum|null` |   |

### hasSum

### setSum

Sum aggregator.

| **Parameter** ||
|---|---|
| **Name** | **Description** |
| `var` | `https://docs.cloud.google.com/php/docs/reference/cloud-firestore/latest/V1.StructuredAggregationQuery.Aggregation.Sum` |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `$this` |   |

### getAvg

Average aggregator.

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.cloud.google.com/php/docs/reference/cloud-firestore/latest/V1.StructuredAggregationQuery.Aggregation.Avg|null` |   |

### hasAvg

### setAvg

Average aggregator.

| **Parameter** ||
|---|---|
| **Name** | **Description** |
| `var` | `https://docs.cloud.google.com/php/docs/reference/cloud-firestore/latest/V1.StructuredAggregationQuery.Aggregation.Avg` |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `$this` |   |

### getAlias

Optional. Optional name of the field to store the result of the
aggregation into.

If not provided, Firestore will pick a default name following the format
`field_<incremental_id++>`. For example:

    AGGREGATE
      COUNT_UP_TO(1) AS count_up_to_1,
      COUNT_UP_TO(2),
      COUNT_UP_TO(3) AS count_up_to_3,
      COUNT(*)
    OVER (
      ...
    );

becomes:

    AGGREGATE
      COUNT_UP_TO(1) AS count_up_to_1,
      COUNT_UP_TO(2) AS field_1,
      COUNT_UP_TO(3) AS count_up_to_3,
      COUNT(*) AS field_2
    OVER (
      ...
    );

Requires:

- Must be unique across all aggregation aliases.
- Conform to [document field name](https://docs.cloud.google.com/php/docs/reference/cloud-firestore/latest/V1.Document#_Google_Cloud_Firestore_V1_Document__getFields__) limitations.

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `string` |   |

### setAlias

Optional. Optional name of the field to store the result of the
aggregation into.

If not provided, Firestore will pick a default name following the format
`field_<incremental_id++>`. For example:

    AGGREGATE
      COUNT_UP_TO(1) AS count_up_to_1,
      COUNT_UP_TO(2),
      COUNT_UP_TO(3) AS count_up_to_3,
      COUNT(*)
    OVER (
      ...
    );

becomes:

    AGGREGATE
      COUNT_UP_TO(1) AS count_up_to_1,
      COUNT_UP_TO(2) AS field_1,
      COUNT_UP_TO(3) AS count_up_to_3,
      COUNT(*) AS field_2
    OVER (
      ...
    );

Requires:

- Must be unique across all aggregation aliases.
- Conform to [document field name](https://docs.cloud.google.com/php/docs/reference/cloud-firestore/latest/V1.Document#_Google_Cloud_Firestore_V1_Document__getFields__) limitations.

| **Parameter** ||
|---|---|
| **Name** | **Description** |
| `var` | `string` |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `$this` |   |

### getOperator

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `string` |   |