【发布时间】:2015-05-18 06:57:04
【问题描述】:
我知道这可能是一个非常愚蠢的问题,但我是 DynamoDB 的新手。
我怀疑是否可以在 DynamoDB 中更新 Range Key 的值。
假设我的表是“TEST”
{
ID : PK/HK
Date : RK
Name : GSI
Add : LSI
}
我要修改Date属性。
表中的初始值为:
{
ID = "344"
Date = "5656"
Name = "ABC"
}
在下面运行此代码。我可以更改 GSI 的 Name 属性。
Map<String,AttributeValue> item = new HashMap<String,AttributeValue>();
item.put("ID", new AttributeValue("344"));
item.put("Date", new AttributeValue("5656"));
Map<String,AttributeValueUpdate> item1 = new HashMap<String,AttributeValueUpdate>();
AttributeValueUpdate update = new AttributeValueUpdate().withValue(new AttributeValue("AMIT")).withAction("PUT");
item1.put("Name", update);
UpdateItemRequest updateItemreq = new UpdateItemRequest("Test",item,item1);
UpdateItemResult updateItemres = dynamoDBUSEast.updateItem(updateItemreq);
但是当我改变这一行时
item1.put("Name", update);
与
item1.put("Date", update);
我遇到了一些错误
Exception in thread "main" com.amazonaws.AmazonServiceException: One or more parameter values were invalid: Cannot update attribute Date. This attribute is part of the key (Service: AmazonDynamoDBv2; Status Code: 400; Error Code: ValidationException; Request ID: HRRP24Q7C48AMD8ASAI992L6MBVV4KQNSO5AEMVJF66Q9ASUAAJG)
at com.amazonaws.http.AmazonHttpClient.handleErrorResponse(AmazonHttpClient.java:820)
at com.amazonaws.http.AmazonHttpClient.executeHelper(AmazonHttpClient.java:439)
at com.amazonaws.http.AmazonHttpClient.execute(AmazonHttpClient.java:245)
at com.amazonaws.services.dynamodbv2.AmazonDynamoDBClient.invoke(AmazonDynamoDBClient.java:2908)
at com.amazonaws.services.dynamodbv2.AmazonDynamoDBClient.updateItem(AmazonDynamoDBClient.java:1256)
那么是否可以更改范围键值?
【问题讨论】:
-
无法更改其唯一键
标签: java amazon-dynamodb