I've had a read through AWS's docs around pagination: http://docs.aws.amazon.com/amazondynamodb/latest/developerguide/QueryAndScan.html#ScanQueryLimit
As their docs specify:
In a response, DynamoDB returns all the matching results within the scope of the Limit value. For example, if you issue a Query or a Scan request with a Limit value of 6 and without a filter expression, DynamoDB returns the first six items in the table that match the specified key conditions in the request (or just the first six items in the case of a Scan with no filter)
Which means that given I have a table called Questions
with an attribute called difficulty
(that can take any numeric value ranging from 0
to 2
) I might end up with the following conundrum:
- A client makes a request, think
GET /questions?difficulty=0&limit=3
- I forward that
3
to the DynamoDB query, which might return0
items as the first 3 in the collection might not be ofdifficulty == 0
- I then have to perform a new query to fetch more
questions
that match that criteria without knowing I might return duplicates, since previously there was noLastEvaluatedKey
given
How can I then paginate based on a query correctly? Something where I'll get as many results as I asked for whilst having the correct offset
via user2061811
No comments:
Post a Comment