0

I have primary_key ('id'/string) and sort_key ('updated_at'/Unix time stamp number). When I query to dynamo DB trough lambda using node.j, I want to fetch results ordered by my sort_key.

I have tried scan but results are not ordered during scan calls. When I do the query it requires to do an operation with my primary key. How can I fetch my data sorted by sort key?

1 Answer 1

2

In your case, you have a composite primary key comprising id plus updated_at. With this type of key you can query for records with a given id, sorted by updated_at.

If you want to sort purely by updated_at, then you need to add a Global Secondary Index on updated_at. This would require the value of updated_at to be unique for each item.

Sign up to request clarification or add additional context in comments.

2 Comments

looks like what ive been looking for ill accept the answer as soon as I confirm. Thank you very much :)
Be sure to understand what attribute projection means (at that same page). You'll need to decide which attributes to project into the GSI.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.