我收到“提供的关键元素与架构不匹配”的错误。 uuid
是我的主分区键。我还有一个 version
的主排序键。我想我可以使用 batchWrite
( 文档)删除所有具有相同 uuid
的项目。
我的 ES6 代码如下:
delete(uuid) {
const promise = new Promise();
const params = {
RequestItems: {
[this.TABLE]: [
{
DeleteRequest: {
Key: { uuid: uuid }
}
}
]
}
};
// this._client references the DocumentClient
this._client.batchWrite(params, function(err, data) {
if (err) {
// this gets hit with error
console.log(err);
return promise.reject(err);
}
console.log(result);
return promise.resolve(result);
});
return promise;
}
不知道为什么它在主键上出错。当我搜索一些不是关键的东西时,我曾经看过一些关于需要其他索引的帖子。但我不相信这里的情况。
原文由 Dave Stein 发布,翻译遵循 CC BY-SA 4.0 许可协议
这是批量写入删除请求示例。此代码已经过测试并且工作正常。如果您根据需要更改此代码,它应该可以工作。
表定义:-
包 - 表名称
包 - 哈希键
“Bag”表中没有分区键
批量写入代码:-
输出:-