Reputation: 8707
I'm trying to get the latest rows of a table, using Dynamoose.
I read about query().ascending()
and query.descending()
, but I need to query the whole table, which requires the hashkey to be empty, as far as I understood. scan()
doesn't support sorting.
Something like:
MyModel
.scan() // 1. scan the whole table
.descending('my_date') // 2. sort by descending by a date
.limit(100) // 3. limit the results to 100
.exec(function(error, data) {
// return error or data
});
Does anyone know how to get the latest rows?
Thanks in advance!
Upvotes: 2
Views: 2681
Reputation: 39206
Neither DynamoDB or Dynamoose API support to get the latest results. You may need to perform this at client side (i.e. write custom code to achieve this result).
DynamoDB API:-
The attribute needs to be defined as SORT key to sort the data by ascending or descending.
Even Dynamoose API doesn't sort the data by all attributes. It sorts the data by sort key only.
Upvotes: 3