Override default 100 limit for .find() in cloud code [SOLVED]

I have a cloud code function that should return an array of about 900 objects, yet the max I can get is 100, any suggestions?


Moralis.Cloud.define("getAllRewards", async (request) => {
  const query = new Moralis.Query("Deposits");
  query.equalTo("payee", request.params.account);
  const results = await query.find();
  let sum = [];
  for (let i = 0; i < results.length; ++i) { 
    sum.push({"amount": results[i].get("weiAmount")});
  }
  return sum;
});

I just had to check the count first and set the limit of the query to the count (code below)

Moralis.Cloud.define("getAllRewards", async (request) => {
  const query = new Moralis.Query("Deposits");
  query.equalTo("payee", request.params.account);
  const count = await query.count(); //ADDED THIS LINE
  query.limit(count); //AND ADDED THIS LINE
  const results = await query.find();
  let sum = [];
  for (let i = 0; i < results.length; ++i) { 
    sum.push({"amount": results[i].get("weiAmount")});
  }
  return sum;
});
1 Like

Nice job Ty keep up the good work :+1:

Thank you very much. It helps.