This question already has an answer here:
I have a cloud code which returns sometimes more than 1000 results , I am not getting how to chain query to get more than 1000 results in following code.
var User = Parse.Object.extend("Journal");
var mainQuery = new Parse.Query(User);
mainQuery.equalTo("user",username);
mainQuery.limit(1000);
mainQuery.find({
success: function(results) {
count = 0;
var avg = 0;
console.log("self:"+results.length);
for(j = 0; j < results.length ; j++)
{
var entry = results[j];
if(strcmp1(day,"All") != 0)
{
var dt = entry.get("created");
var weekDay = dt.getDay();
if(weekDay == day)
{
total += entry.get("Level");
count++;
}
}
else
{
total += entry.get("Level");
count++;
}
}
if(count > 1)
avg = total / count;
response.success(avg);
}
});
limit function is used for raising the default limit of 100 which is max 1000 per query result return cycle .
I am using this code presently. This can fetch more than 1000 results. The values are sorted according to "objectId". You can sort according to "createdAt" by changing accordingly. Final results are stored in result array
var result = [];
var processCallback = function(res) {
result = result.concat(res);
if (res.length == 1000) {
process(res[res.length-1].id);
return;
}
//To print all the ids
for(var i=0;i<result.length;i++){
console.log(result[i].id);
}
}
var process = function(skip) {
var query = new Parse.Query("ObjectName");
if (skip) {
query.greaterThan("objectId", skip);
}
query.limit(1000);
query.ascending("objectId");
query.find().then(function querySuccess(res) {
processCallback(res);
}, function queryFailed(error) {
});
}
process(false);
来源:https://stackoverflow.com/questions/25688005/how-to-get-more-than-1000-results-parse