I have a table with only hash key, now use case requires to create a GSI with creationDate as range key.
I am achieving this by specifying creationDate value as a number in all new items.
But the table already has about 5000 entries with no value set for creationDate and those entries are not included in the result of scan or query operation on GSI. As a solution to this I want to use a default value for all entries with currently no value for creationDate. How do I do this using dynamodbmapper in Java, or is there a way to do it using AWS console ?
The existing items have to be updated individually.
Update the item if the attribute doesn't exists for the given Hash key:-
If the attribute already exists, the following example does nothing; otherwise it sets the attribute to a default value.
UpdateItemSpec updateItemSpec = new UpdateItemSpec().withPrimaryKey("orderId", "75246c41-02c7-48c4-8d4c-d202483e6d2b")
.withReturnValues(ReturnValue.ALL_NEW).withUpdateExpression("set #createDate = if_not_exists (#createDate, :val1)")
.withNameMap(new NameMap().with("#createDate", "createDate"))
.withValueMap(new ValueMap().withNumber(":val1", 1));
UpdateItemOutcome outcome = table.updateItem(updateItemSpec);
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.