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.

preguntada hace 2 años1231 visualizaciones
1 Respuesta
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.

respondido hace 2 años

No has iniciado sesión. Iniciar sesión para publicar una respuesta.

Una buena respuesta responde claramente a la pregunta, proporciona comentarios constructivos y fomenta el crecimiento profesional en la persona que hace la pregunta.

Pautas para responder preguntas