'How to remove attribute from item in DynamoDB table?
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.
javaamazon-web-services">amazon-web-servicesamazon-dynamodb">amazon-dynamodbaws-sdk-java-2.0aws-sdk-java
Solution 1:[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;
}
}
Solution 2:[2]
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
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | mikethe |
Solution 2 | Gaurav |