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

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

问题描述

基于DynamoDb文档,为什么有人会使用 updateItem 而不是 putItem

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


  • PutItem -写一个单项到表格。如果表中存在具有相同主键的项目,则该操作将替换该项目。对于计算预配置的吞吐量消耗,重要的项目大小是两者中的较大者。

  • UpdateItem -修改表。 DynamoDB会考虑更新前后项目的大小。消耗的预配置吞吐量反映了这些项目中较大的一个。即使仅更新项目属性的子集, UpdateItem 仍将消耗全部预配置吞吐量( before和 after中的较大者)项目大小)。

  • 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项目与

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天全站免登陆