DynamoDB: updateItem only if it already exists

By default, DynamoDB will create a new record if the object with the specified index does not exist. Is there any way to stop this? I could just query the table for the key before updating, but it would be nice to do all this with one query.

+4
source share
3 answers

The key point is that it is ConditionExpressionconsidered on different data sets depending on the operation PutItem  or UpdateItem performed .

PutItem.

ConditionExpression DynamoDB Key - , range , 1, .

, DynamoDB PutItem , , .

, CUSTOMER_CONTACTS customer_id/contact_email , ConditionExpression = "#contact_email <> :email". PutItem ConditionalCheckFailedException, ( ).

. DynamoDB .

.

, ConditionExpression = "#contact_email <> :email", . ? UpdateItem 1 , , .

UpdateItem ConditionExpression , , . .

+1

, attribute_not_exists check in Condition Expressions.

PutItem, DynamoDB , , . , . attribute_not_exists ,

http://docs.aws.amazon.com/amazondynamodb/latest/developerguide/Expressions.SpecifyingConditions.html

0

id = :id, id - ( ), :id - ( , ).

. true ( , ), .

0

Source: https://habr.com/ru/post/1648853/


All Articles