aggregate method
Returns a query that can perform the given aggregations.
The returned query, when executed, calculates the specified aggregations over the documents in the result set of this query without actually downloading the documents.
Using the returned query to perform aggregations is efficient because only the final aggregation values, not the documents' data, is downloaded. The returned query can perform aggregations of the documents in cases where the result set is prohibitively large to download entirely (thousands of documents).
@param aggregateSpec An AggregateSpec
object that specifies the aggregates
to perform over the result set. The AggregateSpec specifies aliases for each
aggregate, which can be used to retrieve the aggregate result.
@example
const aggregateQuery = col.aggregate(query, {
countOfDocs: count(),
totalHours: sum('hours'),
averageScore: average('score')
});
const aggregateSnapshot = await aggregateQuery.get();
const countOfDocs: number = aggregateSnapshot.data().countOfDocs;
const totalHours: number = aggregateSnapshot.data().totalHours;
const averageScore: number | null = aggregateSnapshot.data().averageScore;
Implementation
external AggregateQuery aggregate(JSObject aggregateSpec);