2014-12-03 87 views
1

超過900級的對象我有云招聘這樣的代碼:Parse.com:無法創建使用雲工作

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調用。但也許別人知道更好?

+0

您應該使用'Parse.Object.saveAll'。 – eth3lbert 2014-12-03 10:36:19

回答

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.") 
     } 
    } 
});