I'm still learning how to use Parse and I'm working with migrating a subset of a database with 49 items. I read that Parse saveAll should be able to handle batches of 70-100 with no issues but when ever I run the code below, Parse always only saves 20 items.
I run a query to draw out all items with .each(), then I create new parse Objects and insert them into an array. Once the each() finishes, the array contains all 49 elements but when saveAll runs, only 20 items are saved.
I read thru promises but I'm not certain how they'll work with saveAll, additionally, most people here don't seem to be having any issues with saveAll.
I've tested the code below as a background and cloud function.
Parse.Cloud.job("testEach2", function(request, response) {
var eachQuery = new Parse.Query("test_csv");
var Item = Parse.Object.extend("Item");
var toSave = [];
eachQuery.each(
function(result) {
var item = new Item();
item.set("name",result.get("v_products_name_1"))
console.log(item.name)
toSave.push(item)
}, {success: function(result) {
response.success();
console.log(toSave.length);
Parse.Object.saveAll(toSave).then(function(results){
console.log("Objects were saved!");
response.success("Awesome");
},function(error){
console.log(error);
response.error(error);
});
}, error: function() {} });
});
You should call response.success();
only after Parse.Object.saveAll()
is finished. Remove the first response.success();
from your success
callback.