0
[{
    "forms": [{
        "id": "f1",
        "title": "Form1",
        "update_history": [{
            "version": "A",
            "updated_at": "2016-12-10 12:12:10"
        }, {
            "version": "B",
            "updated_at": "2017-01-01 05:17:19"
        }, {
            "version": "C",
            "updated_at": "2017-02-07 03:22:39"
        }]
    },{
        "id": "f2",
        "title": "Form2",
        "update_history": [{
            "version": "B",
            "updated_at": "2016-12-10 12:12:10"
        }, {
            "version": "C",
            "updated_at": "2017-01-01 05:17:19"
        }, {
            "version": "D",
            "updated_at": "2017-02-07 03:22:39"
        }]
    },{
        "id": "f3",
        "title": "Form13",
        "update_history": [{
            "version": "A",
            "updated_at": "2016-12-10 12:12:10"
        }, {
            "version": "E",
            "updated_at": "2017-01-01 05:17:19"
        }, {
            "version": "F",
            "updated_at": "2017-02-07 03:22:39"
        }]
    }]
}]

I have above data stored in Dynamo-DB table. forms object is parent object. There are 3 list data in update_history nested object. I want all the List data which have version A. Please suggest me query for the same.

1 Answer 1

1

The update_history is a List data type contains Map objects on it. This is basically a complex structure on DynamoDB data model.

Assuming, the version A will always be the first occurrence on the List, the below FilterExpression should work. If this assumption is not true, the FilterExpression wouldn't work.

This is the only option available for the above data model. If you can redesign to have only Map or List data type, then we can think about alternate solution.

The below code is on JavaScript:-

You can convert it into PHP code. The AWS SDK API concept is same on all languages.

FilterExpression : 'update_history[0].version = :versionVal',
    ExpressionAttributeValues : {
        ':versionVal' : 'A'
    }
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.