如何将新的键值对放入 DynamoDB 中的映射中?(爪哇)

2023-06-27Java开发问题
1

本文介绍了如何将新的键值对放入 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 中的映射中?(爪哇)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

The End

相关推荐

如何使用 JAVA 向 COM PORT 发送数据?
How to send data to COM PORT using JAVA?(如何使用 JAVA 向 COM PORT 发送数据?)...
2024-08-25 Java开发问题
21

如何使报表页面方向更改为“rtl"?
How to make a report page direction to change to quot;rtlquot;?(如何使报表页面方向更改为“rtl?)...
2024-08-25 Java开发问题
19

在 Eclipse 项目中使用西里尔文 .properties 文件
Use cyrillic .properties file in eclipse project(在 Eclipse 项目中使用西里尔文 .properties 文件)...
2024-08-25 Java开发问题
18

有没有办法在 Java 中检测 RTL 语言?
Is there any way to detect an RTL language in Java?(有没有办法在 Java 中检测 RTL 语言?)...
2024-08-25 Java开发问题
11

如何在 Java 中从 DB 加载资源包消息?
How to load resource bundle messages from DB in Java?(如何在 Java 中从 DB 加载资源包消息?)...
2024-08-25 Java开发问题
13

如何更改 Java 中的默认语言环境设置以使其保持一致?
How do I change the default locale settings in Java to make them consistent?(如何更改 Java 中的默认语言环境设置以使其保持一致?)...
2024-08-25 Java开发问题
13