简体   繁体   English

使用 python 从 DynamoDB 查询所有行

[英]Query all rows from DynamoDB using python

As far as I went, there is very little information on how to retrieve all rows of a DynamoDB.就我而言,关于如何检索 DynamoDB 的所有行的信息很少。

I used table.scan() But when using this method you have a limit, so you will not get all the items.我使用了table.scan()但是当使用这个方法时你有一个限制,所以你不会得到所有的项目。

I tried table.query() But it says: Either the KeyConditions or KeyConditionExpression parameter must be specified in the request.我试过table.query()但它说: Either the KeyConditions or KeyConditionExpression parameter must be specified in the request.

Thanks a lot非常感谢

The only way is to use table.scan() but you will need to add consistent read.唯一的方法是使用 table.scan() 但您需要添加一致的读取。

Scan uses eventually consistent reads when accessing the data in a table; Scan 在访问表中的数据时使用最终一致性读取; therefore, the result set might not include the changes to data in the table immediately before the operation began.因此,结果集可能不包括操作开始前对表中数据的更改。 If you need a consistent copy of the data, as of the time that the Scan begins, you can set the ConsistentRead parameter to true .如果您需要数据的一致副本,在扫描开始时,您可以将 ConsistentRead 参数设置为 true 。 Here is a link to the documentation.这是文档的链接。 https://boto3.amazonaws.com/v1/documentation/api/latest/reference/services/dynamodb.html#DynamoDB.Client.scan https://boto3.amazonaws.com/v1/documentation/api/latest/reference/services/dynamodb.html#DynamoDB.Client.scan

If LastEvaluatedKey is empty, then the "last page" of results has been processed and there is no more data to be retrieved.如果 LastEvaluatedKey 为空,则结果的“最后一页”已被处理,不再有数据可检索。

If LastEvaluatedKey is not empty, it does not necessarily mean that there is more data in the result set.如果 LastEvaluatedKey 不为空,并不一定意味着结果集中有更多数据。 The only way to know when you have reached the end of the result set is when LastEvaluatedKey is empty.知道何时到达结果集末尾的唯一方法是 LastEvaluatedKey 为空。

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

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