DynamoDB Upsert with condition on numeric attribute

1

Is it possible to do an upsert (insert if the item does not exist, update otherwise) with a condition on a specific attribute using the Update() call?

For example I have a UpdatedTime that I only want to allow to be greater when upserting, otherwise do nothing. This is fine if the item already exists, but the conditional will fail if there is no existing item. Is it possible to do this with a single call to DynamoDB? The alternative is to check the error and then do an Insert(), but now I have a race to deal with.

asked 2 years ago1206 views
1 Answer
1

To answer my own question (not sure why it was not obvious, maybe writing it down helped...):

The conditional needs to be (1) attribute_not_exists OR the (2) <= condition on the numeric field.

On the first UpdateItem() call, condition (1) is true and (2) is always false. On subsequent calls, (1) is false, but (2) can potentially be true.

answered 2 years ago

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.

Guidelines for Answering Questions