简体   繁体   中英

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?

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM