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

查看:22
本文介绍了如果我们使用重复的哈希键插入 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.

注意

为确保新项目不会替换现有项目,请使用条件 put 操作,并将主键属性的 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天全站免登陆