Reputation: 93
I have a nodejs code which will perform a batchWriteItem operation on AWS dynamodb which is working fine. Currently even if an item is already present with the same key, it will get overwritten with the new item having same key. But I would like to know is there any way of preventing the overwrite of an item if it already exists. Basically if an item already exist already, I do not want it be updated with new item having same key. When I searched,what I found is we have to make a query of each item and check the keys and if it doesn't exist only add it as an item for batchWriteItem. But that will take time for reading and comparing
Upvotes: 2
Views: 1914
Reputation: 3029
Using WriteBatchItem
you can only Put
or Delete
items. When you Put
, you overwrite.
What you want to use is the UpdateItem
, it will create or update the item. The downside is that it updates the items one by one, there is no UpdateBatchItem.
So your only choice to update an item is to use UpdateItem
.
I do not recommend you to Get
, then Put
the record. You will consume twice more capacity units. Update
works with "one" write capacity unit.
Upvotes: 4