You need the async library for this function
var saveBatch = function(source, callback, limit) {
limit = limit || 20;
var nbSlices = Math.ceil(source.length / limit), i = 0;
async.whilst(function() {
return i < nbSlices;
},
function(cb) {
var chunk = source.slice(i * limit, (i+1) * limit);
Parse.Object.saveAll(chunk)
.then(function() {
i++;
cb();
},
function(err) {
cb(err);
});
},
callback);
}
And you'd use it like
var myArrayOfObjects = [......]
saveBatch(myArrayOfObjects, function(err) {
if (err) {
console.log(err)
}
else {
console.log(myArrayOfObjects.length + " objects saved!")
}
})