如何使用FilterExpression将DynamoDB查询/扫描应用于PHP中的嵌套Json attribues

时间:2017-03-22 10:03:12

标签: amazon-dynamodb amazon-dynamodb-streams

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”。我希望使用子对象id(值为f6yy)使用business_id创建整个记录。请建议。

1 个答案:

答案 0 :(得分:1)

以下过滤器表达式应该有效。

JavaScript: -

上过滤表达式
FilterExpression : 'forms.f6yy.id = :formIdVal',
    ExpressionAttributeValues : {           
        ':formIdVal' : 'f6yy'
    }

<强> PHP: -

'FilterExpression' => 'forms.f6yy.id = :formIdVal',