6
votes

I just started figuring out DynamoDB.

I have a simple table has date attribute(ex. 20160101) as HASH and created_at attribute(ex. 20160101185332) as RANGE.

I'd like to get latest N items from the table.

First, SCAN command does not have ScanIndexForward option. I think it's not possible with SCAN.

Next, QUERY command. It seems to be work if I repeat QUERY command several times to get enough number of items(cuz, I don't know how many items have same key value). - for example, I can query using today first and repeat for the day before if the result does not give enough items.

How can I do the job more efficiently? Or, can I query without KEY value?

1

1 Answers

2
votes

as you described your table, you cant do it more efficiently, and you cant query dynamodb without KEY(hash) value

look at the answer here: dynamodb get earliest inserted distinct values from a table