2

I am trying to remove a value from a List/array in DynamoDB.

I understand I need to use REMOVE which requires the index of the value to remove.

Is it possible to find the index of a given value and remove the value in a single updateItem?

If not, what is the best way to perform this action?

Much appreciated.

1 Answer 1

3

Looks like you can't do such atomic removes from a list in DynamoDB. So you are right, to remove an item from a list, you have to find the index of the item first, it's impossible to do both steps in a single UpdateItem operation. You read the item first, and then perform the update.


Such atomic value remove actions as you are looking for, are possible only on sets: NS (number set), SS (string set), BS (binary set).

When using DELETE action in UpdateItem, you have to specify a list of values to remove, you don't have to find their indexes before performing the action (actually, set is an unordered collection, so elements do not have indexes)

So if your use case allows using a set instead of list, I would suggest doing so. (The differences between set and list are: a set holds unordered, unique elements of the same type, while list is an ordered collection of values with no restrictions on the data types)

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

1 Comment

Thank you, I got that impression but that's much clearer.

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.