Back to Firebase Js Sdk

AggregateFunction class

docs-devsite/firestore_lite_pipelines.aggregatefunction.md

12.12.12.6 KB
Original Source

Project: /docs/reference/js/_project.yaml Book: /docs/reference/_book.yaml page_type: reference

{% comment %} DO NOT EDIT THIS FILE! This is generated by the JS SDK team, and any local changes will be overwritten. Changes should be made in the source code at https://github.com/firebase/firebase-js-sdk {% endcomment %}

AggregateFunction class

A class that represents an aggregate function.

<b>Signature:</b>

typescript
export declare class AggregateFunction 

Constructors

ConstructorModifiersDescription
(constructor)(name, params)Constructs a new instance of the <code>AggregateFunction</code> class

Properties

PropertyModifiersTypeDescription
exprTypeExpressionType

Methods

MethodModifiersDescription
as(name)Assigns an alias to this AggregateFunction. The alias specifies the name that the aggregated value will have in the output document.

AggregateFunction.(constructor)

Constructs a new instance of the AggregateFunction class

<b>Signature:</b>

typescript
constructor(name: string, params: Expression[]);

Parameters

ParameterTypeDescription
namestring
paramsExpression<!-- -->[]

AggregateFunction.exprType

<b>Signature:</b>

typescript
exprType: ExpressionType;

AggregateFunction.as()

Assigns an alias to this AggregateFunction. The alias specifies the name that the aggregated value will have in the output document.

<b>Signature:</b>

typescript
as(name: string): AliasedAggregate;

Parameters

ParameterTypeDescription
namestringThe alias to assign to this AggregateFunction.

<b>Returns:</b>

AliasedAggregate

A new AliasedAggregate that wraps this AggregateFunction and associates it with the provided alias.

Example

typescript
// Calculate the average price of all items and assign it the alias "averagePrice".
firestore.pipeline().collection("items")
  .aggregate(field("price").average().as("averagePrice"));