2014-09-23 80 views
2

我在一張表上有大約13000條記錄(HashTag -classname)。我想在單個查詢中檢索它們。但解析只允許每個查詢1000。任何其他方式獲得的所有記錄..獲取表中的所有記錄-Parse.com

ParseQuery<ParseObject> query = ParseQuery.getQuery("HashTag"); 
query.whereExists("Tag"); query.orderByAscending("Type"); query.setLimit(1000); 
query.findInBackground(new FindCallback<ParseObject>() { 

           @Override 
           public void done(List<ParseObject> list, 
             ParseException e) { 
            // TODO Auto-generated method stub 
            if (e == null) 
            { 
             if (list.size() > 0) { 
              for (int i = 0; i < list.size(); i++) { 
               ParseObject p = list.get(i); 
               String tagid = p.getString("Tag"); 
               String Type = p.getString("Type"); 
               class2 c2 = new class2(); 
               c2.type = "" + Type; 
               c2.tag = "" + tagid; 
               listClass2.add(c2); 



              } 

             } 
+0

在分析數據瀏覽器中看到的 「更多」 下拉菜單,然後 「出口類」 – 2014-09-24 18:04:05

回答

1
//Declare a global variable for storing the complete data 
private static List<ParseObject>allObjects; 
allObjects=new ArrayList<ParseObject>(); 
ParseQuery<ParseObject>query3=ParseQuery.getQuery("HashTag"); 
query3.whereExists("Tag"); 
query3.setLimit(1000); 
query3.findInBackground(getallobjects()); 
int limit=1000; 
int skip=0; 
//callback method: 
private FindCallback<ParseObject>getallobjects(){ 
    return new FindCallback<ParseObject>(){ 
     @Override 
     public void done(List<ParseObject>list,ParseException e){ 
      allObjects.addAll(list); 
      if(list.size()==limit){ 
       skip=skip+limit; 
       ParseQuery<ParseObject>query=ParseQuery.getQuery("HashTag"); 
       query.setSkip(skip); 
       query.setLimit(limit); 
       query.findInBackground(getallobjects()); 
      }else{ 
       //you have full data in allobjects 
       for(int i=0;i<allObjects.size();i++){} 
      } 
     }}} 
1

當然,你可以運行多個查詢同一個表,用查詢的skip財產1000每次遞增:

  1. 獲取總數通過query.count()記錄,並用它來設置一個「跳過」變量
  2. 運行爲每個1000只記錄一個新的查詢,相應地更新您跳過酒店
  3. 處理記錄爲正常時,每個查詢返回

事情是這樣的:

ParseQuery<ParseObject> query = ParseQuery.getQuery("HashTag"); 
    query.whereExists("Tag"); 
    query.countInBackground(new CountCallback() { 
     public void done(int count, ParseException e) { 
     if (e == null) { 
       // The count request succeeded. Run the query multiple times using the query count 
      int numQueries = Math.ceil(count/1000); //Gives you how many queries to run 
      for(int skipNum = 0; l < numQueries; l++){ 
      ParseQuery<ParseObject> query = ParseQuery.getQuery("HashTag"); 
      query.whereExists("Tag"); query.orderByAscending("Type"); 
      query.setLimit(skipNum * 1000); 
      query.findInBackground(new FindCallback<ParseObject>() { 
       //Run your query as normal here 

      } 
      } 
     } else { 
      // The request failed 
     } 
     } 
+0

這會增加API查詢電話? – 2014-09-23 15:42:40

+0

是的,您必須爲每個查詢進行API調用,因此13000個記錄= 13個查詢。 (順便說一句,這也是解析自己所建議的解決方案 - 請參閱https://www.parse.com/questions/how-can-i-get-thousands-of-records-at-a- time) – 2014-09-24 13:01:17

0
ParseQuery<ParseObject> query = new ParseQuery<ParseObject>("TestObject"); 
      query.findInBackground(new FindCallback<ParseObject>() { 
       @Override 
       public void done(List<ParseObject> list, ParseException e) { 
        for(ParseObject p : list){ 

         Log.d("--", (String) p.get("foo")+p.getCreatedAt()); 
        } 
       } 
      }); 
相關問題