3

I need some help to get an item from a nested JSONschema in DynamoDB. I will explain to you the schema and you can tell me if it's possible.

The schema is:

{
    "updated_at": "2018/05/02 08:32:10",
    "created_at": "2018/05/02 08:32:10",
    "updated_by": "igor",
    "created_by": "igor",
    "application": [
        {
            "name": "driver app",
            "features": [
                {
                    "name": "passenger list",
                    "settings": [],
                    "description": "feature for passenger list",
                    "id": 2
                }
            ],
            "id": 1,
            "url": "play store"
        },
        {
            "name": "passsenger app",
            "features": [],
            "id": 2,
            "url": "play store"
        }
    ],
    "address": "New York",
    "id": 4,
    "url": "https://airlink.moovex.com",
    "name": "airlink",
    "service_locations": [
        {
            "title": "IL",
            "latitude": 32,
            "longitude": 35
        }
    ]
}

I need to fetch from my application list the object by id with a query.

1
  • Unfortunately, this is not possible on dynamodb. The CONTAINS function requires all the attributes in the object to match the item in the list. For example, it requires id, url, features etc. Commented May 15, 2018 at 14:59

1 Answer 1

3

I'm not sure this answers your question but, if you need to retrieve the application list for an object with a specific id, that's what you would do

import boto3

DyDB = boto3.resource('dynamodb')

table = DyDB.Table('YourTableName')

response = table.query(
    ProjectionExpression='application',
    KeyConditionExpression=Key('id').eq(4) # where 4 is the id you need to query
)

# this is just to test the result
for app in response['Items'][0]['application']:
    print(app['id'])

The response will give you back (in the list Items), the application attribute with the list of applications inside it

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.