5

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?

Jagdish Idhate
  • 7,513
  • 9
  • 35
  • 51

2 Answers2

13

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

jshaipuka
  • 221
  • 1
  • 4
0

Have you tried

.loadAll()

The docs aren't too clear on what this does, but it sounds promising.

F_SO_K
  • 13,640
  • 5
  • 54
  • 83