在DynamoDB表项目中的列表类型属性中添加或删除条目 [英] Add or remove an entry from a List type attribute in a DynamoDB table item

查看:513
本文介绍了在DynamoDB表项目中的列表类型属性中添加或删除条目的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个非常简单的类,具有字符串类型的主键和List类型的属性.我想编写APIS,用于在属性列表中添加和删除项目并将更改保存回DDB.

I have a very simple class, with a string type primary key and List type attributes. I want to write APIS for adding and removing an item from the attribute list and saving the changes back to DDB.

我能想到的最简单的解决方案是: -阅读列表(如果存在) -如果存在,请从列表类型"属性中删除或添加该条目 -将修改后的对象放回

The simplest solution I can think of is: - Read the list (if it exists) - If it exists, remove or add that entry from the List type attribute - Put the modified object back

是否有更干净/更简单的方法通过DynamoDB Java API执行此操作?在我在此处发布此问题之前,我花了很多时间进行查找.

Is there a cleaner/simpler way to do this via DynamoDB java API? I spent quite some time looking it up, before I posted this question here.

推荐答案

我刚刚通读了UpdateItem API,其中涉及删除集合类型属性:

I just read the UpdateItem API thoroughly which talks about deleting set type attributes:

DELETE-如果未为DELETE指定值,则删除属性及其值.指定值的数据类型必须与现有值的数据类型匹配.如果指定了一组值,那么将从旧组中减去这些值.例如,如果属性值是集合[a,b,c],而DELETE操作指定了[a,c],则最终属性值是[b].指定空集是错误的.

DELETE - Removes the attribute and its value, if no value is specified for DELETE. The data type of the specified value must match the existing value's data type.If a set of values is specified, then those values are subtracted from the old set. For example, if the attribute value was the set [a,b,c] and the DELETE action specifies [a,c], then the final attribute value is [b]. Specifying an empty set is an error.

这篇关于在DynamoDB表项目中的列表类型属性中添加或删除条目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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