Reference documentation and code samples for the Cloud Firestore Client class Aggregate.
Represents Aggregate properties.
Example:
$count = Aggregate::count();
$count->alias('count');
echo json_encode($count->getProps());
Namespace
Google \ Cloud \ FirestoreMethods
alias
Set the aggregate alias.
Example:
$count = Aggregate->count();
$count->alias('total');
echo $count->props()['alias'];
| Parameter | |
|---|---|
| Name | Description |
alias |
string
The alias for aggregate. |
| Returns | |
|---|---|
| Type | Description |
Aggregate |
|
getProps
Get the array representation for the aggregate.
| Returns | |
|---|---|
| Type | Description |
array |
|
static::count
Creates count aggregation properties.
Example:
$count = Aggregate::count();
| Returns | |
|---|---|
| Type | Description |
Aggregate |
|
static::sum
Creates sum aggregation properties.
Example:
$sum = Aggregate::sum('field_to_aggregate_upon');
Result of SUM aggregation can be a integer or a float.
Sum of integers which exceed maxinum integer value returns a float.
Sum of numbers exceeding max float value returns INF.
Sum of data which contains NaN returns NaN.
Non numeric values are ignored.
| Parameter | |
|---|---|
| Name | Description |
field |
string
The relative path of the field to aggregate upon. |
| Returns | |
|---|---|
| Type | Description |
Aggregate |
|
static::avg
Creates average aggregation properties.
Example:
$avg = Aggregate::avg('field_to_aggregate_upon');
Result of AVG aggregation can be a float or a null.
Average of empty valid data set return null.
Average of numbers exceeding max float value returns INF.
Average of data which contains NaN returns NaN.
Non numeric values are ignored.
| Parameter | |
|---|---|
| Name | Description |
field |
string|null
The relative path of the field to aggregate upon. |
| Returns | |
|---|---|
| Type | Description |
Aggregate |
|