Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Pagination in DynamoDB

I have a requirement for to show the search result on the jsp with maxcount of 10 and it should have a pagination to traverse back and forward as pagination functionality.

Dynamodb has a lastevaluatedkey, but it doesn't help to go back to the previous page, though I can move to the next result set by the lastevaluatedKey.

Can anybody please help on this.

I am using Java SPRING and DynamoDB as the stack.

Thanks Satya

like image 780
user1989933 Avatar asked Jan 18 '13 09:01

user1989933


1 Answers

To enable forward/backward, all you need is to keep

the first key, which is hash key + sort key of the first record of the previously returned page (null if you are about to query the first page).

and

the last key of the retrieved page, which is hash key + sort key of the last record of the previously returned page

Then to navigate forward or backward, you need to pass in below parameters in the query request:

Forward: last key as the ExclusiveStartKey, order = ascend

Backward: first key as the ExclusiveStartKey, order = descend

I have achieved this in a project in 2016. DynamoDB might provide some similar convenient APIs now, but I'm not sure as I haven't checked DynamoDB for a long time.

like image 196
Ray Liu Avatar answered Sep 20 '22 20:09

Ray Liu