Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

I have limit of 12 items, but dynamodb query always returns 10 only

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.

enter image description here

Am I missing something?

like image 646
Jagdish Idhate Avatar asked Dec 12 '17 08:12

Jagdish Idhate


1 Answers

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).

like image 56
jshaipuka Avatar answered Oct 17 '22 11:10

jshaipuka