Difference between DynamoDb PutItem vs UpdateItem?

前端 未结 3 1846
情话喂你
情话喂你 2020-12-25 10:21

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


  • PutItem - Writes a single ite
3条回答
  •  -上瘾入骨i
    2020-12-25 11:25

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

    Eg.

    I have an item like:

    userId = 1
    Name= ABC
    Gender= Male
    

    If I use PUT item with

    UserId = 1
    Country = India
    

    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

    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)

    Hope this make sense.

提交回复
热议问题