How to retrieve more than 1000 rows from Parse.com?

前端 未结 10 1041
独厮守ぢ
独厮守ぢ 2020-11-29 19:54

I have been using Parse to retrieve a data for a list view. Unfortunately they limit requests to 100 by default to a 1000 max. I have well over that 1000 max in my class. I

10条回答
  •  臣服心动
    2020-11-29 20:40

    **EDIT : Below answer is redundant because open source parse server doesn't put any limit on max rows to be fetched

     //instead of var result = await query.find();
        query.limit(99999999999);//Any value greater then max rows you want
        var result = await query.find();**
    

    Original answer:

    Javascript / Cloud Code

    Here's a clean way working for all queries

    async function fetchAllIgnoringLimit(query,result) {
      const limit = 1000;
      query.limit(limit);
      query.skip(result.length);
    
      const results = await query.find();
      result = result.concat(results)
    
      if(results.length === limit) {
        return await fetchAllIgnoringLimit(query,result );
      } else {
        return result;
      }
    
    }
    

    And here's how to use it

    var GameScore = Parse.Object.extend("GameScore");
    var query = new Parse.Query(GameScore);
    //instead of var result = await query.find();
    var result = await fetchAllIgnoringLimit(query,new Array());
    console.log("got "+result.length+" rows")
    

提交回复
热议问题