Build a Simple dApp in 3 Mins - Cloud Functions (Part 5)

https://docs.moralis.io/guides/build-a-simple-dapp-in-3-mins-cloud-functions-part-5

The tutorial is functioning in every sense with the exception of the result appearing to be truncated. Is this working as designed? In the example it returns 10 average gas costs, yet when I run the example code it only returns 2 list items. Can someone explain why the shorter list? I have gone in and edited my version of the cloud function to have a limit of 100 but this does not appear to have any affect.

Please see the results from my browser below:

what is the code that you have in cloud functions that returns that average gas?

Thanks for responding.

Here it is:

Moralis.Cloud.define(“getAvgGas”, async function (request) {
const query = new Moralis.Query(“EthTransactions”);
const pipeline = [
{
group: {
// group by “from_address”
objectId: “$from_address”,
// add computed property avgGas
// get average and convert wei to gwei
avgGas: { $avg: { $divide: ["$gas_price", 1000000000]} },
},
},
{ sort: { avgGas: -1 } }, // sort by avgGas high to low
{ limit: 100 }, // only return top 10 results – uped to 100 to see if all get returned
];

// the master key is required for aggregate queries
const results = await query.aggregate(pipeline, { useMasterKey: true });
return results;
})

maybe are only two from addresses in your particular case

Sure, of course that makes sense, it can’t return data that’s not there… :wink: Maybe I’m not understanding the source of the data. Do you know where the data for the averages is coming from?

If it’s somehow coming from records I am generating, perhaps I could create more records to get the result I’m looking for. If its not in my control then well, I guess I’ll just have to get over it. :laughing:

it should be from the transactions that you have on your server in EthTransactions, but grouped by from_address

Thanks, I suspected that, I will just need to generate some more transactions. That is “Average” is average for “me”, totally makes sense now. :+1:

That was it: