如何将新的键值对放入 DynamoDB 中的映射中?(爪哇)
我有一个 DynamoDB 属性,其值是从数字到字符串的映射.我正在尝试放入一个新的键值对.根据我的阅读,这似乎是可能的,但我不知道如何.
I have a DynamoDB attribute whose value is a map from a Number to a String. I am trying to put in a new key-value pair. From what I've read, this seems to be possible, but I don't know how.
我认为解决方案类似于以下链接中的解决方案:
I assume the solution is similar to the one in the link below:
如何在 AWS DynamoDB 文档 API 上更新地图或列表?
但我不相信这个例子是在地图上添加一个新项目.有人可以告诉我如何将项目放入地图吗?
But I do not believe the example is on putting in a new item to a map. Could someone show me how to put in an item to a map?
谢谢.
我不想获取该项目,在本地进行更改,然后将其放回原处.我正在与可能同时交互的多个客户合作(我假设 dynamo 的更新确保不会出现竞争条件).
I do not want to get the item, locally make the changes, and put it back. I am working with multiple clients who might interact concurrently (and I assume the update by dynamo ensures there will be no race conditions).
推荐答案
使用 UpdateItem 的以下参数,当 map.#number 在地图中不存在时,您可以在 #number 处添加地图条目:
With the following arguments to UpdateItem, you can condition adding a map entry at #number when map.#number does not exist in the map already:
UpdateExpression = "SET map.#number = :string"
ExpressionAttributeNames = { "#number" : "1" }
ExpressionAttributeValues = { ":string" : "the string to store in the map at key value 1" }
ConditionExpression = "attribute_not_exists(map.#number)"
相关文章