I am wondering how could I paginate in AWS Dynamodb database in the most efficient way possible. I have found a few solutions playing with the ExclusiveStartKey like this:
var params = {
"TableName" : "abcd",
"ExpressionAttributeNames" : {"#someexperssion":"someexperssion"},
"ExpressionAttributeValues" : {":someexperssion" : "value"},
"Limit" : 20,
"ExclusiveStartKey" : {"id": "9ee10f6e-ce6d-4820-9fcd-cabb0d93e8da"}
};
The problem I found with these solutions is that You always have to know the last key ExclusiveStartKey. When I only want to retrieve the 4th page with a 10 items, do I have to query all the items before the 4th page to know what is the last key?
I would like to access the db only once when trying to get the nth page. Is that possible?
Thank You all!