I am new to amazon web services. I want to retrieve all the entries in the dynamo DB table which have a particular word in their hash key. It is similar to using like operator in oracle DB. How can I do it? If its not possible, how do I retrieve all the entries in the table without giving any constraint on the hash key so that later I can iterate over all of them to match the word?
How to retrieve all the entries with hash key as a particular pattern in dynamo DB?
Asked Answered
General DynamoDB thoughts:
Please, do not think of DynamoDB as you would of MySQL. DynamoDB is only a key:value store with a couple of niceties.
The fundamental of key:value store is:
Either you know the key, and get your value;
Either you don't, and you get the whole table.
In DynamoDB specific case, you can
- Retrieve an item knowing the whole key with
GetItem
- Retrieve all items under a given
hash_key
, possibly applying a filter, withQuery
- Retrieve the whole table, possibly applying filters, with
Scan
This said, Scan
is both slow and expensive. You should never use it otherwise your design is most probably wrong.
Specific to your question:
In your case, it sounds like you will want to split your key into a
hash_key
range_key
Then you could use Query
to get all the items sharing hash_key
. With Query
, you may apply filters like BEGINS_WITH
to narrow you scope.
Please note that all (hash_key
, range_key
) tuples needs to be unique.
It should be worth mentioning that even if you do a query, and want to apply a filter within the query - the results can only be a max of 1MB, meaning that if the query exceeds 1MB, you will have have all of your data to be filtered on. –
Aeromarine
Makes me wish AWS and blogs didn't market DynamoDB as a 'not only SQL' datastore. I've never worked with any key value store where you couldn't ask for the list of keys. In their documentation I've not seen a head-nod to the requirement for maintaining your keys in another table/lookup. @yadutaf's comment on Scans is spot on--it's almost like they added that feature so you can know when you're using the wrong datastore. –
Eve
© 2022 - 2024 — McMap. All rights reserved.