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.

已提问 2 年前1243 查看次数
1 回答
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.

已回答 2 年前

您未登录。 登录 发布回答。

一个好的回答可以清楚地解答问题和提供建设性反馈,并能促进提问者的职业发展。

回答问题的准则

相关内容