Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Querying DynamoDB with unique hash attributes?

I'm planning to have a User table with UserName as the hash key and a LastLoginDate attribute (among others).

I would like to be able to query the table for something like: All users that have not logged in for the last month.

How would I do this with DynamoDB?

I have been looking at local secondary indices, and thought of making LastLoginDate a secondary index. But how I understand the documentation, secondary indices only help order results for the same hash key, and in my case each user will have a unique UserName. Does this make such a secondary index pointless?

Thanks in advance!

like image 336
Felix Avatar asked Jan 26 '26 13:01

Felix


2 Answers

You are correct, you must always query by HashKey, unless you do a full table scan.

Doing a fulltable scan, you can look at each and every entry in your table and compare their LastLoginDate. This can quickly become unscalable depending on how many users you have.

like image 123
prestomation Avatar answered Jan 28 '26 03:01

prestomation


You can Create GSI on LastLoginDate and apply your logic by Firing the Query to GSI. This might help to get result faster instead of scanning foe HASH key and checking for LastLoginDate and applying logic.

like image 35
Bhavik Joshi Avatar answered Jan 28 '26 02:01

Bhavik Joshi



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!