How to use pagination on dynamoDB

北慕城南 提交于 2019-12-11 18:44:00

问题


How can you make a paginated request (limit, offset, and sort_by) using dynamoDB? On mysql you can:

SELECT... LIMIT 10 OFFSET 1 order by created_date ASC

I'm trying this using nodejs, and in this case created_date isn't the primary key, can I query using sort key created_date?

This is my users table

{
    "user_id": "asa2311",
    "created_date": "2019/01/18 15:05:59",
    "status": "A",
    "rab_item_id": "0",
    "order_id": "1241241",
    "description": "testajabroo",
    "id": "e3f46600-1af7-11e9-ac22-8d3a3e79a693",
    "title": "test"
},
{
    "user_id": "asa2311",
    "status_id": "D",
    "created_date": "2019/01/18 14:17:46",
    "order_id": "1241241",
    "rab_item_id": "0",
    "description": "testajabroo",
    "id": "27b5b0d0-1af1-11e9-b843-77bf0166a09f",
    "title": "test"
},
{
    "user_id": "asa2311",
    "created_date": "2019/01/18 15:05:35",
    "status": "A",
    "rab_item_id": "0",
    "order_id": "1241241",
    "description": "testajabroo",
    "id": "d5879e70-1af7-11e9-8abb-0fa165e7ac53",
    "title": "test"
}

回答1:


Pagination in DynamoDB is handled by setting the ExclusiveStartKey parameter to the LastEvaluatedKey returned from the previous result. There is no way to start after a specific number of items like you can with OFFSET in MySQL.



来源:https://stackoverflow.com/questions/54250864/how-to-use-pagination-on-dynamodb

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!