spring-data-dynamodb-examples
spring-data-dynamodb-examples copied to clipboard
Update specific attribute
Hi, I am learning spring and dynamoDB. I'd like to know how can I update specific attribute of a record using spring-data-dynamodb? Just like the example in https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/JavaDocumentAPICRUDExample.html ?
For example, I want to update user status from "blocked" to "active". Instead of passing the whole details of user I want to do something like ` Table table = dynamoDB.getTable(tableName);
try {
UpdateItemSpec updateItemSpec = new UpdateItemSpec().withPrimaryKey("Id", 121)
.withUpdateExpression("set #status = :val1").withNameMap(new NameMap().with("#status", "NewAttribute"))
.withValueMap(new ValueMap().withString(":val1", "active")).withReturnValues(ReturnValue.ALL_NEW);
UpdateItemOutcome outcome = table.updateItem(updateItemSpec);
}
catch (Exception e) {
System.err.println("Failed to add new attribute in " + tableName);
System.err.println(e.getMessage());
}`
Regards, Gail