7

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?

1 Answer 1

13

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.

Sign up to request clarification or add additional context in comments.

1 Comment

Bear in mind of course that sets and array are semantically different, so as long as ordering isn't important or can be rebuilt sets are definitely the way to go

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.