duanke1286 2017-03-14 11:56
浏览 201

如何在PHP中使用dynamoDB查询获取Json嵌套属性值

[{
    "forms": [{
        "id": "52b55960-023e-11e7-9140-f3c1d163524b",
        "title": "Default Form",
        "update_history": [{
            "version": "1",
            "updated_at": "2016-12-10 12:12:10"
        }, {
            "version": "2",
            "updated_at": "2017-01-01 05:17:19"
        }, {
            "version": "3",
            "updated_at": "2017-02-07 03:22:39"
        }, {
            "version": "4",
            "updated_at": "2017-03-03 02:28:56"
        }, {
            "version": "5",
            "updated_at": "2017-01-11 07:01:22"
        }]
    }]
}]

I have above Json stored in Dynamo-DB table. forms object is parent object. I have stored form updated detail version and updated_at in update_history nested object. I want updated_at of version of 2. Please suggest me, what is wrong in below query. I got empty result.

`$response = $client->scan([
       'TableName' => 'TableName',
       'ProjectionExpression' => 'Json.forms.update_history.updated_at',
                    'ExpressionAttributeValues' => [
                            ':val1' => ['S' => '52b55960-023e-11e7-9140-f3c1d163524b'],
                            ':val2' => ['S' => '2']
                            ],
                    'FilterExpression' => 'id = :val1 and Json.forms.update_history.version = :val2',
        ]);` 
  • 写回答

1条回答 默认 最新

  • dongyun234854 2017-03-14 13:51
    关注

    Please refer the DocumentPath example in the below link and try to use deference operator.

    For a nested attribute, you construct the document path using dereference operators.

    If you don't know the deference operator (i.e. index), you can't filter the data as you have tried.

    http://docs.aws.amazon.com/amazondynamodb/latest/developerguide/Expressions.AccessingItemAttributes.html#DocumentPaths

    Example:-

    Accessing List Elements:-

    MyList[0]
    AnotherList[12]
    ThisList[5][11]
    

    Accessing Map Elements:-

    MyMap.nestedField
    MyMap.nestedField.deeplyNestedField
    

    You have the combination of both Map and List, you need to FilterExpression accordingly.

    评论

报告相同问题?

悬赏问题

  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 关于大棚监测的pcb板设计
  • ¥15 stm32开发clion时遇到的编译问题
  • ¥15 lna设计 源简并电感型共源放大器
  • ¥15 如何用Labview在myRIO上做LCD显示?(语言-开发语言)
  • ¥15 Vue3地图和异步函数使用