pagination dynamodb code example
Example 1: pagination mongodb
def skiplimit(page_size, page_num):
"""returns a set of documents belonging to page number `page_num`
where size of each page is `page_size`.
"""
# Calculate number of documents to skip
skips = page_size * (page_num - 1)
# Skip and limit
cursor = db['students'].find().skip(skips).limit(page_size)
# Return documents
return [x for x in cursor]
Example 2: dynamodb pagination nodejs
const getAllData = async (params) => {
console.log("Querying Table");
let data = await docClient.query(params).promise();
if(data['Items'].length > 0) {
allData = [...allData, ...data['Items']];
}
if (data.LastEvaluatedKey) {
params.ExclusiveStartKey = data.LastEvaluatedKey;
return await getAllData(params);
} else {
return data;
}
}