Skip to content

Instantly share code, notes, and snippets.

@markmssd
Forked from clemblanco/main.js
Created March 19, 2017 01:27
Show Gist options
  • Save markmssd/09e7282ade279330ce9ebd7be4f7a96c to your computer and use it in GitHub Desktop.
Save markmssd/09e7282ade279330ce9ebd7be4f7a96c to your computer and use it in GitHub Desktop.
Parse - CloudCode - Retrieve all objects from a specific Parse class without limitation
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