简体   繁体   English

我有一个 boto3 lambda function,它使用 table.scan 来扫描 dynamoDB。 我想将有限的数据发送到前端以显示 10 个条目,不能使用查询

[英]I have a boto3 lambda function which uses table.scan to scan the dynamoDB. I want to send limited data to frontend to show 10 entries, cant use query

I want someone to help me with how to implement pagination in boto3 without query, NextToken.我希望有人帮助我如何在没有查询的情况下在 boto3 中实现分页,NextToken。 I want the dynamoDB data to be sent to the frontend but 10 entries at a time and every time send the next 10 entries to the frontend.我希望将 dynamoDB 数据发送到前端,但一次发送 10 个条目,并且每次都将接下来的 10 个条目发送到前端。 First I thought I could use the query but the primary key would filter most of the data and I want all the results, just 10 entries at a time.首先,我以为我可以使用查询,但主键会过滤大部分数据,我想要所有结果,一次只需要 10 个条目。 Also on the frontend, it has to be like page1(10 entries), page2(next 10 ), like that.同样在前端,它必须像 page1(10 entries), page2(next 10) 那样。

To implement pagination with a DynamoDB scan operation you have to save the LastEvaluatedKey value that was returned from the first scan, and pass that as the ExclusiveStartKey on the next scan.要使用 DynamoDB 扫描操作实现分页,您必须保存从第一次扫描返回的LastEvaluatedKey值,并在下一次扫描时将其作为ExclusiveStartKey传递。

On the first scan operation ( page == 0 ) you would simply pass Limit=10 in the query parameters.在第一次扫描操作( page == 0 )中,您只需在查询参数中传递Limit=10

On the second scan operation ( page == 1 ) you would pass Limit=10, ExclusiveStartKey=<lastScanResult.LastEvaluatedKey> .在第二次扫描操作 ( page == 1 ) 中,您将传递Limit=10, ExclusiveStartKey=<lastScanResult.LastEvaluatedKey>

Note that you will have to pass the LastEvaluatedKey value to the frontend as part of your result data, the frontend will have to store that in memory, and send it as part of the request data when it requests the next page.请注意,您必须将LastEvaluatedKey值作为结果数据的一部分传递给前端,前端必须将其存储在 memory 中,并在请求下一页时将其作为请求数据的一部分发送。

There's no direct approach from what I'm getting your question.从我得到的问题中没有直接的方法。

Above mentioned approach by Mark B is good but not for your case you won't be able to move to any page other than next or go to previous page directly with this approach.上面提到的 Mark B 的方法很好,但不适合你的情况,你将无法使用这种方法直接移动到下一页或 go 到上一页以外的任何页面。

You can implement a not so cost efficient approach by adding a field to db of page number and using a lambda function to maintain pagination in db您可以通过向页码数据库添加一个字段并使用 lambda function 来维护数据库中的分页,从而实现一种不太经济高效的方法

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

相关问题 AWS Lambda python boto3 dynamodb 表扫描 - 调用扫描操作时发生错误(ValidationException):ExpressionAttributeNames - AWS Lambda python boto3 dynamodb table scan - An error occurred (ValidationException) when calling the Scan operation: ExpressionAttributeNames 使用 boto3 完整扫描 dynamoDb - Complete scan of dynamoDb with boto3 Python boto3 AWS Dynamodb 表“客户端”object 与“资源”object 上的查询和扫描方法 - Python boto3 AWS Dynamodb table Query & Scan methods on 'Client' object vs 'Resource' object Boto3 DynamoDb 扫描包含过滤器不返回任何结果 - Boto3 DynamoDb scan with contains filter not returning any results 使用 boto3 和 dynamodb 扫描查找 2 个日期之间的项目 - Finding items between 2 dates using boto3 and dynamodb scan 我想在异步 function、python 中使用 boto3 - I want to use boto3 in async function, python 如何从 AWS 扫描 dynamodb 表 Lambda function - How to scan the dynamodb table form the AWS Lambda function 如何获取扫描 dynamodb 表返回的项目的大小? - How can I get the size of items returned by scan dynamodb table? 如何使用 AWS DynamoDB 的并行扫描对特定 GSI 运行扫描? - How can i use Parallel Scan of AWS DynamoDB to run scan on a specific GSI? Java Lambda 用于 dynamodb 的分页扫描 - Java Lambda for Pagination scan for dynamodb
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM