Skip to content Skip to sidebar Skip to footer

Dynamodb Update Operation Without Using The Key Attribute

The use case: I have a bid table which holds the bid on Loades. One Load can have multiple Bids. The Bid status is new for every bid. Once the bid is accepted by the Admin(The pers

Solution 1:

I do not believe there is a batch update option in DDB. You may have some luck with Transactions, which do allow updates but come with additional overhead. Alternatively, you may want to consider solving this problem with a sparse index.

For example, lets say your main table has the following bid information

bid table

and lets say you want to mark BID#1 as the accepted bid. Instead of introducing an attribute to define the accepted/rejected status, you could create a global secondary index on the accepted bid. For example

enter image description here

In this example, I created an additional attribute named GSIPK (you could name it anything, this is just an example). Logically, your index would look like this:

enter image description here

Notice that the index only contains the winning bid from LOAD#1. None of the other bids are in the index because none of the other bid items have a GSIPK attribute.

This may not satisfy all your access patterns around bids. However, it's a decent strategy to separate winning bids from rejected bids without having to do a bulk update of attributes.

If you did want to create an status attribute that you could set to the rejected/accepted status, you might consider setting the default status to rejected when inserting a bid. That way, you only have to update the single accepted bid once the bidding is done.

Post a Comment for "Dynamodb Update Operation Without Using The Key Attribute"