2

I have an item whose particular attribute I want to remove using SDK 2.x from DynamoDB. How do I do this? I am using enhanced DynamoDB for table management. Here's a code sample:

DynamoDbTable<T> mappedTable = AwsConfig.getTableSchema(schema, clazz);
T updatedRecord = mappedTable.updateItem(request -> {
                request.ignoreNulls(true);
                request.item(record);
});

I would appreciate a solution using enhanced DynamoDB client.

Mark Rotteveel
  • 100,966
  • 191
  • 140
  • 197
Anwesh Mohapatra
  • 107
  • 1
  • 10

2 Answers2

1

Not sure what you mean by remove attribute, if you refer to not have an attribute persisted in dynamoDB you can use @DynamoDbIgnore

@DynamoDbBean
public class SomeDynamoDBEntity {

    @DynamoDbIgnore
    public String getType() {
        return this.type;
    }
}
mikethe
  • 147
  • 1
  • 2
  • 14
1

Set the variable value to null in your record class object. And do not set ignoreNulls to true. EnhancedClient will remove that respective attribute from the item with UpdateItemEnhancedRequest.

Ref: read ignoreNulls in documentation here

Gaurav
  • 11
  • 2