If I created the following NoSQL table using DynamoDB, how might I query for the item with the largest ID value whose Unused value is true without scanning the entire table?
(I have zero experience with cloud platforms and NoSQL.)
+--------+------------+-----------+
| ID | Unused | Token |
+--------+------------+-----------+
| 1 | True | ... |
+--------+------------+-----------+
| 2 | True | ... |
+--------+------------+-----------+
| 3 | True | ... |
+--------+------------+-----------+
| 4 | False | ... |
+--------+------------+-----------+
| 5 | False | ... |
+--------+------------+-----------+
You create a Global Secondary Index with
Unusedas the partition key andIdas the sort key.Using a Query you can do the following:
SELECT * FROM mytable.myindex WHERE Unused='True' LIMIT 1 DESCThis blog will help you to understand the pros and cons.