DynamoDb PutItem 与 UpdateItem 之间的区别? [英] Difference between DynamoDb PutItem vs UpdateItem?

查看:27
本文介绍了DynamoDb PutItem 与 UpdateItem 之间的区别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

根据 DynamoDb 文档,为什么有人会使用 updateItem 而不是 putItem?

Based on DynamoDb documentation why would anyone use updateItem instead of putItem?

  • PutItem - 将单个项目写入表格.如果表中存在具有相同主键的项目,则操作替换该项目.为了计算预配置的吞吐量消耗,重要的项目大小是两者中较大的一个.
  • UpdateItem - 修改表中的单个项目.DynamoDB 会考虑更新前后项目的大小.消耗的预配置吞吐量反映了这些项目大小中较大的一个.即使您只更新项目属性的一个子集,UpdateItem 仍将消耗全部预配置吞吐量(之前"和之后"项目大小中的较大者).
  • PutItem - Writes a single item to a table. If an item with the same primary key exists in the table, the operation replaces the item. For calculating provisioned throughput consumption, the item size that matters is the larger of the two.
  • UpdateItem - Modifies a single item in the table. DynamoDB considers the size of the item as it appears before and after the update. The provisioned throughput consumed reflects the larger of these item sizes. Even if you update just a subset of the item's attributes, UpdateItem will still consume the full amount of provisioned throughput (the larger of the "before" and "after" item sizes).

推荐答案

两者的主要区别在于,PutItem会替换整个项目,而UpdateItem会更新它.

The main difference between the two is, PutItem will Replace an entire item while UpdateItem will Update it.

例如

我有一个类似的项目:

userId = 1
Name= ABC
Gender= Male

如果我使用 PUT 项

If I use PUT item with

UserId = 1
Country = India

这将替换 Name 和 Gender,现在新的 Item 是 UserId 和 Country.而如果你想将一个项目从 Name = ABC 更新到 Name = 123 你必须使用 UpdateItem

This will replace Name and Gender and now new Item is UserId and Country. While if you want to update an item from Name = ABC to Name = 123 you have to use UpdateItem

您可以使用 Put 项目来更新它,但您需要发送所有参数,而不仅仅是您要更新的参数,因为它会用新属性替换项目.(在内部它删除项目并添加新项目)

You can use Put item to update it but you need to send all the parameters instead of just the Parameter you want to update because it Replaces the item with the new attribute.(Internally it Deletes the item and Add new item)

希望这是有道理的.

这篇关于DynamoDb PutItem 与 UpdateItem 之间的区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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