[英]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.