如何将新的键值对放入 DynamoDB 中的映射中?(爪哇) [英] How to put a new key-value pair into a map in DynamoDB? (java)

查看:13
本文介绍了如何将新的键值对放入 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)"

这篇关于如何将新的键值对放入 DynamoDB 中的映射中?(爪哇)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆