不允许在dynamoDB中重复

时间:2015-10-08 17:57:11

标签: amazon-web-services amazon-dynamodb

我正在尝试使用以下代码插入一行:

Item item = new Item().withPrimaryKey("id", id).withString(
                "owner", owner);

if (properties != null) {
    item.withMap("property", properties);
}

Expected expected = new Expected(id).notExist();

return table.putItem(item, expected).toString();

如果输入" id"则不应该更新。已提供的ID已存在于表中。但是,这仍然使用新值更新表中的条目。

我在这里做错了什么?

1 个答案:

答案 0 :(得分:1)

constructor is for the attribute name时,您正在为Expected构造函数提供属性值。

  

public Expected(java.lang.String attrName)

您应该更改使用参数/哈希键值id

Expected expected = new Expected(id).notExist();

使用属性名称

Expected expected = new Expected("id").notExist();