DynamoDB:updateItem(仅当它已经存在时) [英] DynamoDB: updateItem only if it already exists

查看:330
本文介绍了DynamoDB:updateItem(仅当它已经存在时)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

默认情况下,如果不存在具有指定索引的对象,则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:updateItem(仅当它已经存在时)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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