如果使用重复的哈希键插入dynamo DB,会发生什么情况? [英] what will happen if we insert into dynamo DB with a duplicate hash key?

查看:122
本文介绍了如果使用重复的哈希键插入dynamo DB,会发生什么情况?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试插入dynamo DB.当我调用putItem函数时,如果哈希键已经存在于数据库中会发生什么? PutItemResult对象是否包含可以告诉我们是否尝试重复的哈希条目的内容?我想避免运行另一个查询来检查是否存在我正在使用的哈希键的条目.

I am trying to insert into dynamo DB. When I call the putItem function what will happen if the hash key is already present in the DB? Does the PutItemResult object contain something which can tell us if a duplicate hash entry was attempted? I want to avoid running another query to check if there is an entry with the hash key I am using.

推荐答案

如果在现有主键上插入一项,则除非使用期望值",否则它将被覆盖.这是官方文档的介绍:

If you insert an item on an existing primary key, it will be overwritten unless you use the "expected values". Here is the introduction of the official documentation:

http://docs.amazonwebservices.com/amazondynamodb/latest/developerguide/API_PutItem.html

创建一个新项目,或将旧项目替换为新项目(包括所有属性).如果指定表中已经存在具有相同主键的项目,则新项目将完全替换现有项目.您可以执行条件放置(如果不存在具有指定主键的项,则插入新项),或者如果现有项具有某些属性值,则替换现有项.

Creates a new item, or replaces an old item with a new item (including all the attributes). If an item already exists in the specified table with the same primary key, the new item completely replaces the existing item. You can perform a conditional put (insert a new item if one with the specified primary key doesn't exist), or replace an existing item if it has certain attribute values.

注意

为确保新项目不会替换现有项目,请使用一个条件放置操作,将一个或多个主键属性的Exists设置为false.

To ensure that a new item does not replace an existing item, use a conditional put operation with Exists set to false for the primary key attribute, or attributes.

否则,您也可以使用UpdateItem来更新现有项目的字段: http: //docs.amazonwebservices.com/amazondynamodb/latest/developerguide/API_UpdateItem.html

Otherwise, you can also use UpdateItem to update fields of a pre-existing item: http://docs.amazonwebservices.com/amazondynamodb/latest/developerguide/API_UpdateItem.html

这篇关于如果使用重复的哈希键插入dynamo DB,会发生什么情况?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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