简体   繁体   中英

Boto3 DynamoDB: Most Efficient way to query "key" not begins with "SomeValue"

My keys are: {'pk': 'PRODUCT', 'sk':'EQ#TEMP000001'}

So, in the beginning, it is a temporary product and once it is promoted it changes to

{'pk': 'PRODUCT', 'sk':'EQ#BDJDS000001'}

I need to query the data to find all temp product and non-temp products

I am using this code

response = ddb_table.query(
    KeyConditionExpression=Key('pk').eq(f"PRODUCT") Key('sk').begins_with("EQ#"),
    FilterExpression=Key('Code').begins_with('TEMP'),
)

Where code holds only code value like BDJDS000001

How can I query non-temp products?

response = ddb_table.query(
KeyConditionExpression=Key('pk').eq(f"PRODUCT") Key('sk').begins_with("EQ#"),
FilterExpression=Not(Key('Code').begins_with('TEMP')),
)

It's just a hunch but can you try using this?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM