如何在dynamodb上使用java sdk从stringset中删除元素

时间:2019-05-22 21:03:33

标签: database amazon-web-services amazon-dynamodb dynamodb-queries

我有一个项目,其属性为stringset类型的“用户”,其中包含2个元素“ u1”,“ u2”。 我正在尝试从“用户”中删除“ u1”

但是出现以下错误: com.amazonaws.services.dynamodbv2.model.AmazonDynamoDBException:无效的UpdateExpression:语法错误;令牌:“:u”,附近:“ [:u]”(服务:AmazonDynamoDBv2;状态代码:400;错误代码:ValidationException;

这是我使用的代码:

         UpdateItemSpec updateItemSpec = new UpdateItemSpec() 
            .withPrimaryKey(hashKeyFieldName, hashKeyValue)
            .withUpdateExpression("delete #us[:u]") 
            .withNameMap(new NameMap() 
            .with("#us", stringSetFieldName)) 
            .withValueMap(new ValueMap() 
            .withString(":u", "u1")) 
            .withReturnValues(ReturnValue.ALL_NEW);  
            UpdateItemOutcome outcome =  table.updateItem(updateItemSpec);

0 个答案:

没有答案