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

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

问题描述

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

I have a very simple class, with a string type primary key and List type attributes. I want to write an API 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:

  1. 阅读列表(如果存在)
  2. 如果存在,从列表类型属性中删除或添加项目
  3. 把修改过的对象放回去

是否有更简洁/更简单的方法通过 DynamoDB java API 做到这一点?

推荐答案

我刚刚通读了 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天全站免登陆