Created
March 18, 2016 17:20
-
-
Save clemblanco/644eae2426a50cb2b98d to your computer and use it in GitHub Desktop.
Parse - CloudCode - Retrieve all objects from a specific Parse class without limitation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Parse.Cloud.define("retrieveAllObjects", function(request, status) { | |
var result = []; | |
var chunk_size = 1000; | |
var processCallback = function(res) { | |
result = result.concat(res); | |
if (res.length === chunk_size) { | |
process(res[res.length-1].id); | |
} else { | |
status.success(result); | |
} | |
}; | |
var process = function(skip) { | |
var query = new Parse.Query(request.params.object_type); | |
if (skip) { | |
query.greaterThan("objectId", skip); | |
} | |
if (request.params.update_at) { | |
query.greaterThan("updatedAt", request.params.update_at); | |
} | |
if (request.params.only_objectId) { | |
query.select("objectId"); | |
} | |
query.limit(chunk_size); | |
query.ascending("objectId"); | |
query.find().then(function (res) { | |
processCallback(res); | |
}, function (error) { | |
status.error("query unsuccessful, length of result " + result.length + ", error:" + error.code + " " + error.message); | |
}); | |
}; | |
process(false); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Consumed by using either a Promise (or not, it's up to you):