0
[{
    "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 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.