Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update specific attribute #2

Open
kgmercado opened this issue Mar 24, 2018 · 0 comments
Open

Update specific attribute #2

kgmercado opened this issue Mar 24, 2018 · 0 comments

Comments

@kgmercado
Copy link

kgmercado commented Mar 24, 2018

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant