[英]Scan or Query operation on DynamoDB using python Boto3
I have users table, users have user_id field.我有用户表,用户有user_id字段。
I need to get all the user details with given list, like ["1234","3456"].我需要使用给定列表获取所有用户详细信息,例如 ["1234","3456"]。
There is no contain like queries in Boto3. Boto3 中没有包含类似查询。
I'm using我正在使用
response = table.scan(FilterExpression=Attr('user_id').is_in(["1234","3456"]))
But I'm not getting the expected results.但我没有得到预期的结果。
Correct me If I missed anything.如果我错过了什么,请纠正我。
One question that you need to answer is: user_id is your DynamoDB Hash/Partition Key?您需要回答的一个问题是:user_id 是您的 DynamoDB 哈希/分区键吗? If it is, then the operation that you are looking for is: BatchGetItem.如果是,那么您要查找的操作是:BatchGetItem。 You can see how it works here .你可以在这里看到它是如何工作的。
If user_id is not your Partition/Hash Key, a first (and wrong) solution would be to scan the entire table and filter its data (a very expensive method that should be avoided at all costs).如果 user_id 不是您的分区/哈希键,第一个(也是错误的)解决方案是扫描整个表并过滤其数据(一种非常昂贵的方法,应该不惜一切代价避免)。 A second, more efficient solution would be to create a global index (GSI) using user_id as Hash/Partition Key and project the data to be returned in the index.第二种更有效的解决方案是使用 user_id 作为哈希/分区键创建全局索引 (GSI),并在索引中投影要返回的数据。 You can learn more about GSI's here .您可以在此处了解有关 GSI 的更多信息。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.