如何将 DynamoDB 表中的属性值更新为“”?
一种选择是将项目放入一个文档中,然后将所有属性复制到一个新文档中,除了值要更新为“”的属性,然后调用 putitem,这将基本上替换整个项目(因为哈希键存在) ) 并且由于我不再拥有该属性,它将被删除。
注意:我可以简单地删除项目,但我的要求是更新多个属性值,其中一个为空。
如果有的话,请给我建议一个更好的方法。
提前致谢。
最佳答案
DynamoDB 允许使用 UpdateItemRequest(Java SDK) 在现有行中进行更新。
像下面的例子:
Map<String, AttributeValueUpdate> updateItems = new HashMap<String, AttributeValueUpdate>();
updateItems.put("columnToRemove", new AttributeValueUpdate()
.withAction(AttributeAction.DELETE));
updateItems.put("columnToRemove2", new AttributeValueUpdate()
.withAction(AttributeAction.DELETE));
UpdateItemRequest updateItemRequest = new UpdateItemRequest()
.withTableName(tableName)
.withKey(itemKey)
.withAttributeUpdates(updateItems);
UpdateItemResult result = client.updateItem(updateItemRequest);
关于amazon-dynamodb - 在 dynamodb 中将属性值更新为空白 (""),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9939675/