I'm using dynamodb npm to query dynamodb
When I query as below, though I set limit as 12 items, It always returns 10 items
TableDB
.query(lang)
.filter('users').in(['case1','case2'])
.attributes(['offerId', 'lang'])
.ascending()
.usingIndex('lang-date-index')
.limit(12)
.exec((err, data) => {
console.log(data)
}
I don't want to query again using lastEvaluateKey
just for next 2 items.
Am I missing something?
Dynamo applies limit first and only then filters. See Scan limit. This means, if your table has 3 items in the order below :
Dog1
Cat1
Dog2
You filter by dogs and your read limit is 2 then you get following result set:
Dog1
The dynamo response will also provide LastEvaluatedKay which is the last read primary key on your table. Set this LastEvaluatedKay as ExclusiveStartKey in your next results. Here's a similar example of pagination loop for dynamo (in java).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With