Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to retrieve all the entries with hash key as a particular pattern in dynamo DB?

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?

like image 752
coder Avatar asked Oct 05 '12 06:10

coder


1 Answers

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

  1. Retrieve an item knowing the whole key with GetItem
  2. Retrieve all items under a given hash_key, possibly applying a filter, with Query
  3. 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.

like image 180
yadutaf Avatar answered Oct 06 '22 01:10

yadutaf