0

I have an attribute in my table that is of type Document (JSON) where the value is a count:

{ "item1" : "5", "item2" : "7" }

Is there a way for the DynamoDB Document API to increment the values of the map atomically? My application will have several hosts incrementing the values, so simply using puts will not work as they will overwrite each other.

I know for integer attributes, we can have atomic counting with set #count = #count + :countVal in the update expression. Is there something similar for working with Documents?

Also, I noticed that there is no way for DynamoDBMapper to make atomic counter updates, so I do have to use the lower level Document API, right?

1 Answer 1

2

If I understand correctly, you have one of your attributes as a Map, with key value pairs in your table. Dynamodb supports document paths in expressions. So you can do

doc.item1 = doc.item1 + :countVal

You are correct in that dynamodbmapper doesn't support atomic counter updates. It seems to be pretty common to use a combination of dynamodbmapper and lower level API though.

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

2 Comments

What if I have a map like this: { "1.50" : 5, "2.50", 7 }? Since the deference operator for a map is a dot, it doesn't seem like I can access maps where the keys are integers?
Never mind, I just discovered I can use expression attribute names to get around this.

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.