sortkey in DynamoDB query with pagination limit

0

I have a doubt that when we use sortkey in DynamoDB query with pagination limit(example limit=10), whether it gives a sorted list of 10 items of an entire dynamoDB table or just gives the queried items sort list?

If it only gives sort list of queried items how to get the sort list of total dynamoDB table items? for example there is a post table & post has likes how to get the post with highest likes in the table with list of posts in descending order?

1개 답변
6
수락된 답변

Its not possible to obtain order over all keys in a DynamoDB table. The only possible approach would be to Scan the entire table and implement your sorting on the client side.

You could of course use DynamoDB Streams and keep pointers to the top 10 liked posts, if that is something your application intends to show. Then you could simply call BatchGetItems with the 10 listed items.

Another option would be to create a GSI with a single attribute as the PK, for example POSTS and the number of likes as the SK.

PKSKOther
POSTS7Data
POSTS9Data
POSTS11Data

Then you could simply Query your GSI with the key POSTS and use ScanIndexForward=False, Limit=10.

Be warned that this is not a scalable solution as your GSI key is a single value. This will limit your tables writes to approximately 1000WCU per second. That's a decision you can make depending on your throughput needs.

profile pictureAWS
전문가
답변함 2년 전
AWS
전문가
검토됨 2년 전

로그인하지 않았습니다. 로그인해야 답변을 게시할 수 있습니다.

좋은 답변은 질문에 명확하게 답하고 건설적인 피드백을 제공하며 질문자의 전문적인 성장을 장려합니다.

질문 답변하기에 대한 가이드라인

관련 콘텐츠