简体   繁体   English

Boto3 DynamoDB:查询“key”的最有效方法不是以“SomeValue”开头

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

My keys are: {'pk': 'PRODUCT', 'sk':'EQ#TEMP000001'}我的键是: {'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代码仅包含代码值,例如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?这只是一种预感,但您可以尝试使用它吗?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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