如何确定DynamoDB项是否确实被删除? [英] How to determine if a DynamoDB item was indeed deleted?
问题描述
DynamoDB提供了用于删除项目的API.在返回的 DeleteItemOutcome
和 DeleteItemResult
中,没有字段或方法来确定是否找到了密钥并且确实删除了该项.
DynamoDB provides an API for deleting items. In the returned DeleteItemOutcome
and DeleteItemResult
there is no field or method to determine if the key was found and the item was indeed deleted.
找出该商品是否确实存在和删除的唯一方法是请求商品的属性:
The only way to find out if the item was indeed present and deleted, is to request the items' attributes:
新的DeleteItemSpec().withPrimaryKey("key","1").withReturnValues(ReturnValue.ALL_OLD))
但是,这会消耗额外的读取容量.有没有更有效的方法来检查删除结果-找到并删除密钥/无效密钥?
This, however, consumes extra read capacity. Is there a more efficient way to check the delete result - key found and deleted / invalid key?
推荐答案
DeleteItemResult#getAttributes()
is the way to determine if a DeleteItem
operation has actually deleted an item, or not.
如果您指定 ReturnValue.ALL_OLD
且该项目已删除,则返回项目属性的映射,否则返回空映射.这是唯一确定操作是否成功的唯一方法.API没有返回其他确认.
If you specify ReturnValue.ALL_OLD
and the item was deleted, a map of item attributes is returned, otherwise and empty map is returned. This is the only way to know for sure if the operation was successful. No other confirmation is returned by the API.
请记住, DeleteItem
操作每次至少消耗1个写入容量单位.如果删除的项目大于1KB,则消耗的容量将大于1.
Keep in mind that a DeleteItem
operation will consume a minimum of 1 write capacity unit every time. If the deleted item is larger than 1KB, consumed capacity will be more than 1.
这篇关于如何确定DynamoDB项是否确实被删除?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!