Home > database >  Update an attribute in DynamoDB if another attribute exists
Update an attribute in DynamoDB if another attribute exists

Time:11-03

In DynamoDB, is it possible to accomplish the following via an UpdateItem operation?

set attributeA to valueX if the attribute does not exist
set attributeB to valueX if attributeA exists

Both of these must be in the same UpdateItem operation. I'm aware of things like attribute_not_exists and if_not_exists, but I couldn't find an if_exists condition.

How can I accomplish the above task using the low-level APIs?

CodePudding user response:

Sorry, you cannot in one UpdateItem.

You can fetch the item, modify it on the client, then push a new copy. Use optimistic locking to ensure the item wasn't modified in between.

  • Related