简体   繁体   English

具有多个条件的 DynamoDB FilterExpression python 和 boto3

[英]DynamoDB FilterExpression with multiple condition python and boto3

Please I need help writing filter expressions for scanning data in dynamo db tables using python and boto3.我需要帮助编写过滤器表达式以使用 python 和 boto3 扫描 dynamo 数据库表中的数据。

See my code below.请参阅下面的代码。

For some reason unknown to me, this search filter below which I am using is not giving me the right results出于某种我不知道的原因,我在下面使用的这个搜索过滤器没有给我正确的结果

Please advice请指教

dynamo_db = boto3.resource('dynamodb')

table = dynamo_db.Table(TABLE_NAME)

my_kwargs = {
    'FilterExpression': Key('column_1').eq(val_type_1) and Key("column_2").eq("val_type_string")
}
response = table.scan(**my_kwargs)

items = response['Items']
table_item = items[0]

When you use Scan you do not filter on Key .当您使用 Scan 时,您不会过滤Key You filter here is in an attribute so you will need to change Key to Attr .您在此处过滤是在一个属性中,因此您需要将Key更改为Attr

Furthermore you will need to implement pagination if you are scanning more than 1Mb of data:此外,如果扫描超过 1Mb 的数据,则需要实施分页:

https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/Scan.html https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/Scan.html

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

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