Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Add/remove item to array in Amazon DynamoDB

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?

like image 868
Francisco Lozano Avatar asked Mar 03 '12 18:03

Francisco Lozano


1 Answers

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.

like image 64
pw. Avatar answered Sep 23 '22 08:09

pw.