i need some help with DynamoDB. I have table as following:
| Shortener (Hash key) | ShortenedURL (Range key) | LongURL |
|-----------------------------------------------------------------|
| "My webpage url" | "1" | "example.net"|
| "My webpage url" | "6" | "example.com"|
| "My webpage url" | "4" | "example.eu" |
How to retrieve the row with biggest number in "ShortenedURL"? Im totally new to DynamoDB & NoSQL stuff. Using AWS PHP SDK. Tried to search for hours and didnt find anything useful. Everything i tried ended with result like "1" or "4".
To accomplish this, you can Query
with the following arguments:
This will only work if your rangeKey is a Number type. If it's a String, then you can only get lexicographical ordering, so "last" may be weird (these three strings appear in this order: ["1, "10", "2", ...]
).
Does your range key have to be String? If it's a number you can select it to retrieve the biggest one since range key have index which gives them order.
Either way, you can use the Query API and set the index backwards by specifying ScanIndexForward
as false
.