简体   繁体   English

如何在Boto3中将扫描过滤器用于dynamodb

[英]How to use scan filters with boto3 for dynamodb

I'm trying to test sample filters with dynamodb using boto3. 我正在尝试使用boto3用dynamodb测试样本过滤器。 My simple example -written almost identical to the documented one- fails. 我的简单示例-与书面文档几乎完全相同-失败了。 I'm using a Table 'User' that correctly works with .scan : 我正在使用与.scan正确配合的表'User':

In [24]: list(User.scan())
Out[24]: [users_info-dev<giovanni>, users_info-dev<nicola>, users_info-dev<ping>]

When trying to filter on a key: 尝试过滤键时:

User.scan(FilterExpression=Attr('user_id').eq('giovanni'))
---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
...

ValueError: Attribute FilterExpression specified for filter does not exist.

from boto3.dynamodb.conditions import Key, Attr

What's the error and which is the correct way to execute this scan? 有什么错误,什么是执行此扫描的正确方法?

Note: I have not really got the difference between scan and query. 注意:扫描和查询之间并没有真正的区别。 It seems 'query' should be used for filtering on primary key. 似乎应使用“查询”对主键进行过滤。 Having a background on SQL db that sounds wierd to me... 在SQL db上有一个背景对我来说听起来很奇怪...

I didn't realize that I was using a wrappwer around the table provided by pynamodb. 我没有意识到我在使用pynamodb提供的桌子周围的包装纸。 The table was not a table provided by boto3 but by pynamodb, so that the syntax for the query/scan are different (and simpler): 该表不是boto3提供的表,而是pynamodb提供的表,因此查询/扫描的语法是不同的 (并且更简单):

User.scan(User.user_id == 'giovanni')

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

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