有没有办法在不使用UpdateExpression的情况下更新DynamoDB中的项目?
现在,我有这样的事情:
Map<String, AttributeValue> keys = new HashMap<String, AttributeValue>();
keys.put("id", new AttributeValue().withS("123456"));
Map<String, AttributeValue> expressionAttributesValues = new HashMap<String,ATtributeValue>();
expressionAttributes.pput(":newMarks", new AttributeValue().withS("60"));
UpdateItemRequest request = new UpdateItemRequest().
withTableName("MyTable").
withKey(keys).
withUpdateExpression("set marks = :newMarks").
withExpressionAttributeValues(expressAttributeValues);
DynamoDB.updateItem(request);
答案 0 :(得分:0)
我真的不明白为什么你不想使用UpdateExpression,这可能对你有帮助。
这用于添加新项目,但我认为它可以提供帮助。
这是Scala上的示例
def step31(): Unit ={
val awsCredentials: BasicAWSCredentials = new BasicAWSCredentials("XXXX", "XXXXX")
val client: AmazonDynamoDBClient = new AmazonDynamoDBClient(awsCredentials)
val dynamoDB: DynamoDB = new DynamoDB(client)
val tableName = "Movies"
val table: Table = dynamoDB.getTable(tableName)
val year = 2015
val title = "The Big New Movie"
System.out.println("Adding a new item...")
val outcome: PutItemOutcome = table.putItem(new Item()
.withPrimaryKey("year", year, "title", title)
.withJSON("info", Json.obj("plot" -> "Something happens.").toString()))
// .withJSON("info", "{\"plot\" : \"Something happens.\"}"))
System.out.println("PutItem succeeded:\n" + outcome.getPutItemResult)
}