Parse.com:使用云作业无法创建超过9个对象

时间:2014-12-03 10:28:42

标签: javascript parse-platform cloud jobs

我有这样的Cloud Job代码:

Parse.Cloud.job("createMySpecialObjects", function(request, status) {

    var MySpecialObject = Parse.Object.extend("MySpecialObject");

    var count = 20 // 20 is greater than 9!

    for (var i = 0; i < count; i++) {
        var myObject = new MySpecialObject();
        myObject.save();
    }

    status.success("Objects created successfully.");
});

结果我只创建了9个对象。

我认为它每秒连接30个API调用。但也许别人知道的更好?

1 个答案:

答案 0 :(得分:4)

下面的代码段显示了如何使用Parse.Object.saveAll保存多个对象。

Parse.Cloud.job("createMySpecialObjects", function(request, status) {

    var MySpecialObject = Parse.Object.extend("MySpecialObject");

    var count = 20 // 20 is greater than 9!

    var toSaves = [];
    for (var i = 0; i < count; i++) {
        var myObject = new MySpecialObject();
        toSaves.push(myObject);
    }

    Parse.Object.saveAll(toSaves, {
        success: function(saveList) {
            status.success("Objects created successfully.");
        },
        error: function(error) {
            status.error("Unable to save objects.")
        }
    }
});