可以在dynamoDB PHP中更新没有散列键或范围键值的项目吗?

时间:2017-03-24 06:25:45

标签: amazon-dynamodb

Record1: [{
"business_id": 2,
"forms": {
    "f522": {
        "id": "f522",
        "is_deleted": 0,
        "title": "Form 1"
        },
    "f8b6": {
        "id": "f8b6",
        "is_deleted": 0,
        "title": "Form 2" 
       },
    "fw56": {
        "id": "fw56",
        "is_deleted": 0,
        "title": "Form 3" 
      }
}
}]

Record2: [{
"business_id": 3,
"forms": {
    "f788": {
        "id": "f788",
        "is_deleted": 0,
        "title": "Form 11"
    },
    "f6yy": {
        "id": "f6yy",
        "is_deleted": 0,
        "title": "Form 12"
    },
    "f00i": {
        "id": "f00i",
        "is_deleted": 0,
        "title": "Form 13"
    }
}
}]

Record3: [{
"business_id": 4,
"forms": {
    "f839": {
        "id": "f839",
        "is_deleted": 0,
        "title": "Form 21"
    },
    "f1bc": {
        "id": "f1bc",
        "is_deleted": 0,
        "title": "Form 22"
    },
    "f6ac": {
        "id": "f6ac",
        "is_deleted": 0,
        "title": "Form 23"
    }
}
}]

我有3条记录存储在dynamoDB表中。哈希键是business_id。 forms对象是具有子对象(id,is_deleted,title)的父对象。我不知道business_id值。但我只有id值" f6yy"。我想更新is_deleted为1的id(值为f6yy)。请建议整个查询。

2 个答案:

答案 0 :(得分:1)

没有此类查询,因为如果没有为表中的条目提供密钥(business_id),AWS无法识别您要修改的条目。

因此,您需要根据查询更改架构并进行设计,或者将表分解为多个表,以便数据库类似

table 1- business_id  form_id(ex. f6yy etc)
table 2- form_id     form_object(ex. {"is_deleted": 0,"title": "Form 1"})

现在可以在表2上为f6yy进行更新。

答案 1 :(得分:0)

要从DynamoDB表中删除项目,需要分区和排序键。

  

对于主键,您必须提供所有属性。对于   例如,使用简单的主键,您只需提供一个值   对于分区键。对于复合主键,您必须提供   分区键和排序键的值。