我正在尝试遍历json数据并将其添加到dynamoDB表中。它在docClient.put()上中断。有人可以向我指出正确的方向或向我解释我做错了什么吗?
async function SaveJson(json) {
let i;
let promises = [];
for (i = 0; i < json.length; i++) {
promises.push(doSomethingAsync(json[i]));
}
}
function doSomethingAsync(record) {
let params = {
TableName: 'table-name',
Item: {
'Number': record.Number,
'Unit': record.Unit
}
};
console.log('Adding a new item...');
let putItem = new Promise((res, rej) => {
docClient.put(params, function (err, data) { //breaks here
if (err) {
console.log('Error', err);
rej(err);
} else {
console.log('Success', data);
res('data inserted sucessfully');
}
});
});
return putItem;
}