AggregateField is not defined

I'm new to Retool, and I'm trying to perform a basic Aggregate Sum function on my Firestore Collection as follows:

const gigsRef = db.firestore().collection("gigs");
const sumAllShiftsPosted = gigsRef.aggregate({
  totalShiftsPosted: AggregateField.sum("numSpotters"),
const snapshot =  await sumAllShiftsPosted.get();

I'm getting the following error:
'AggregageField' is not defined

What am I missing? Does Retool not support aggregate functions? If so, how do I achieve the result I expect above?

Hi @ikartik90, I don't believe Firestore supports aggregation queries natively in the way you're trying to use it in the code pasted above- I don't see the aggregate method or an AggregateField class in it's JavaScript SDK which is likely why you're seeing that error. However, you should be able to achieve your goal of summing up 'numSpotters' in you 'gigs' collection by creating a javascript transformer that loops through the documents and sums up the numSpotters. Something like this should work:

let data = {{}}; 
let totalShiftsPosted = 0; 
for (let i = 0; i < data.length; i++) { 
   totalShiftsPosted += data[i].numSpotters; 
return totalShiftsPosted;

Your are using an outdated version of firebase-admin. AggregationField is introduced in version 12 so run npm i firebase-admin@12.1.0 in your functions directory

Lindsay, Firestore admin 've already support aggregation queries natively.
You need to update firebase-admin of your Retool js SDK to 12.x.x to support it.
I can do aggregation in my cloud function, but cannot do it with Retool.