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.

posta 2 anni fa1230 visualizzazioni
1 Risposta
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.

con risposta 2 anni fa

Accesso non effettuato. Accedi per postare una risposta.

Una buona risposta soddisfa chiaramente la domanda, fornisce un feedback costruttivo e incoraggia la crescita professionale del richiedente.

Linee guida per rispondere alle domande