且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

DynamoDB:仅当它已经存在时才更新项目

更新时间:2023-02-21 19:04:28

使用条件表达式 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.