如何在CloudKitJS中一次更新多个记录

时间:2016-04-20 17:23:02

标签: node.js cloudkit cloudkit-web-services

我无法一次更新多条记录。我一直收到这个错误: Record updated multiple times in one batch

var options = {  
    zoneName: undefined,
    operationType : 'forceUpdate'
};

CloudKit.getDefaultContainer().publicCloudDatabase.saveRecord(recordsToSave,options).then(function(response) {
    console.log(response)
}).catch(function(err) {
    console.log(err)
})

1 个答案:

答案 0 :(得分:0)

您应该像这样使用Database.saveRecords:

var records = [{
    //for a new record, specify recordName & recordType
    recordName: 'my-record',
    recordType: 'MyRecordType',
    fields: ...
}, {
    //for an existing record, specify recordName & recordChangeTag
    recordName: 'some-other-record',
    recordChangeTag: 'nwerlkjiower',
    fields: ...
}];

CloudKit
    .getDefaultContainer()
    .publicCloudDatabase
    .saveRecords(records)
    .then(function(response) {
       //only some records might have been saved successfully
       if(response.hasErrors) {
           console.log(response.errors);
       }
       console.log(response.records);
    })
    .catch(function(error) {
        console.log(error);
    })