問題描述
我有一個 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)"
這篇關于如何將新的鍵值對放入 DynamoDB 中的映射中?(爪哇)的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!