Question

I am looking at the most efficient atomic way of adding an item to an array inside a DynamoDB object. Right now the only way I see to atomically add something to an array is using a versioned approach: fetching the field to be updated, add/remove the value, and do a conditional update with a "version" field in the row. But this does not look super-efficient to me. Is there any better way to do it?

Was it helpful?

Solution

The UpdateItem operation has both Add and Delete actions. If used on sets, the actions will add/remove the specified values from the set. If used on a number, the Add action will atomically increment or decrement the number.

It's important to remember that DynamoDB actually supports sets, not arrays. Because of this, adding or removing values is inherently atomic.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top