在dynamo数据库中,我以userid作为主键,以recid作为排序键。我想删除用户的所有记录。我正在为Alexa使用Node js lamda函数。
dbHelper.prototype.removeDetails = (userID) => {
return new Promise((resolve, reject) => {
const scanparams = {
TableName: tableName
}
docClient.scan(scanparams, function(err, data) {
if (err)
{
console.error("Unable to scan item. Error JSON:", JSON.stringify(err, null, 2));
return reject(JSON.stringify(err, null, 2))
} // an error occurred
else {
data.Items.forEach(function(obj,i){
console.log(i);
console.log(obj);
var params = {
TableName: tableName,
Key: buildKey(obj),
ReturnValues: 'NONE',
ReturnConsumedCapacity: 'NONE',
ReturnItemCollectionMetrics:
};
docClient.delete(params, function (err, data) {
if (err) {
console.error("Unable to delete item. Error JSON:", JSON.stringify(err, null, 2));
return reject(JSON.stringify(err, null, 2))
}
console.log(JSON.stringify(err));
console.log("DeleteItem succeeded:", JSON.stringify(data, null, 2));
resolve()
});
});
}
});
}); }