Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
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);
});
Owner

Claymm commented Mar 18, 2016

Consumed by using either a Promise (or not, it's up to you):

Parse.Cloud.run('retrieveAllObjects', {
    object_type: "MyClass", // REQUIRED - string: name of your Parse class
    update_at: moment().toDate(), // OPTIONAL - JS Date object: Only retrieve objects where update_at is higher than...
    only_objectId: true|false // OPTIONAL - boolean: the result will only be composed by objectId + date fields, otherwise all attributes are returned.
}).then(function(objects) {
    /* SUCCESS */
    // if objects.length > 0 objects can be looped through
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment