2

I'm trying to query all the Food values in the "Categories" attribute and the "review_count" attribute values that are at least 100. My first time working with scanning tables in DynamoDB through python. I need to use the table.scan function as well. This is what I have tried so far.

resp = table.scan(FilterExpression='(categories = cat1) AND' + '(review_count >= 100)',
        ExpressionAttributeValues={
          ':cat1': 'Food',
        })

Any help would be greatly appreciated. Thanks

MikeMB35
  • 49
  • 3

1 Answers1

1

Assuming table name is test

FilterExpression can't contain constants, should only have either table attributes like categories, review_count and placeholders like :cat1, :rc . So, 100 can be replaced with a variable :rc.

All placeholders should start with : , so, cat1 should be :cat1

table = dynamodb.Table('test')
response = table.scan(
        FilterExpression= 'categories=:cat1 AND review_count>=:rc',
        ExpressionAttributeValues= {
                ':cat1': "Food" ,
                ':rc': 100,
        }
)
data = response['Items']

Important point to note on scan , from documentation

A single Scan operation reads up to the maximum number of items set (if using the Limit parameter) or a maximum of 1 MB of data and then apply any filtering to the results using FilterExpression.

Balu Vyamajala
  • 9,287
  • 1
  • 20
  • 42