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

前端 未结 10 976
独厮守ぢ
独厮守ぢ 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")
    
    0 讨论(0)
  • 2020-11-29 20:42

    YAS (Yet Another Solution!) Using async() and await() in javascript.

    async parseFetchAll(collected = []) {
      let query = new Parse.Query(GameScore);
      const limit = 1000;
    
      query.limit(limit);
      query.skip(collected.length);
    
      const results = await query.find();
    
      if(results.length === limit) {
        return await parseFetchAll([ ...collected, ...results ]);
      } else {
        return collected.concat(results);
      }
    
    }
    
    0 讨论(0)
  • 2020-11-29 20:45

    IMPORTANT None of the answers here are useful if you are using open source parse server then it does limit 100 rows by default but you can put any value in query,limit(100000) //WORKS No need for recursive calls just put the limit to number of rows you want.

    https://github.com/parse-community/parse-server/issues/5383

    0 讨论(0)
  • 2020-11-29 20:48

    I have figured out how to achieve my goal:

    Declare Global Variable

    private static List<ParseObject>allObjects = new ArrayList<ParseObject>();
    

    Create Query

    final ParseQuery parseQuery = new ParseQuery("Objects");
    parseQuery.setLimit(1000);
    parseQuery.findInBackground(getAllObjects());
    

    Callback for Query

    int skip=0;
    FindCallback getAllObjects(){
        return new FindCallback(){
            public void done(List<ParseObject> objects, ParseException e) {
                if (e == null) {
    
                    allObjects.addAll(objects);
                     int limit =1000;
                    if (objects.size() == limit){
                        skip = skip + limit;
                        ParseQuery query = new ParseQuery("Objects");
                        query.setSkip(skip);
                        query.setLimit(limit);
                        query.findInBackground(getAllObjects());
                    }
                    //We have a full PokeDex
                    else {
                        //USE FULL DATA AS INTENDED
                    }
            }
        };
    }
    
    0 讨论(0)
提交回复
热议问题