DynamoDB: updateItem only if it already exists(DynamoDB:仅当它已经存在时才更新项目)
问题描述
默认情况下,如果具有指定索引的对象不存在,DynamoDB 将创建一个新条目.有没有办法阻止这种情况发生?我可以在更新之前在表中查询密钥,但最好在一个请求中完成所有操作.
By default DynamoDB will make a new entry if an object with the specified index doesn't exist. Is there a way to stop this from occurring? I could just query the table for the key before updating, but it would be nice to do it all in one request.
推荐答案
使用条件表达式 id = :id
其中 id
是属性名(或主键名您的情况)和 :id
是值(您要更新的项目的键).
Use conditional expression id = :id
where id
is the attribute name (or primary key name in your case) and :id
is the value (key of the item you want to update).
条件表达式总是在任何写入之前进行评估.如果该表达式的计算结果不是 true
(并且如果该键不存在或不同,则不会),它不会更新或放置新项目.
Conditional expression is always evaluated before any writing. If that expression doesn't evaluate to true
(and it doesn't if that key doesn't exist or is different), it doesn't update or put a new item.
这篇关于DynamoDB:仅当它已经存在时才更新项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:DynamoDB:仅当它已经存在时才更新项目


- PHP Count 布尔数组中真值的数量 2021-01-01
- 从 PHP 中的输入表单获取日期 2022-01-01
- 带有通配符的 Laravel 验证器 2021-01-01
- 如何定位 php.ini 文件 (xampp) 2022-01-01
- SoapClient 设置自定义 HTTP Header 2021-01-01
- Laravel 仓库 2022-01-01
- Oracle 即时客户端 DYLD_LIBRARY_PATH 错误 2022-01-01
- 没有作曲家的 PSR4 自动加载 2022-01-01
- Mod使用GET变量将子域重写为PHP 2021-01-01
- 正确分离 PHP 中的逻辑/样式 2021-01-01