How to get all records using a hash key as a specific template in a dynamo DB?

I am new to amazon web services. I want to get all records in the DB dynamo table that have a specific word in their hash key. It is similar to using a similar operator in an oracle DB. How can I do it? If this is not possible, how can I get all the records in the table without any restrictions on the hash key so that later I can iterate over all of them according to the word?

+4
source share
1 answer

General thoughts DynamoDB:

Please do not think about DynamoDB, like MySQL. DynamoDB is just the key: a repository of values ​​with a few subtleties.

Primary Key: The value is stored:

Or you know the key, and get your value;

Or you will not do this, and get the whole table.

In the specific case of DynamoDB you can

  • Get an item, knowing the whole key, with GetItem
  • Extract all the elements under the given hash_key , possibly using a filter, with Query
  • Extract the entire table, possibly using filters, using Scan

This suggests that Scan is slow and expensive. You should never use it, otherwise your design will most likely be wrong.

Specific for your question:

In your case, it seems that you want to split your key into

  • hash_key
  • range_key

Then you can use Query to get all elements sharing hash_key . With Query you can apply filters such as BEGINS_WITH to narrow the scope.

Note that all ( hash_key , range_key ) tuples must be unique.

+14
source

Source: https://habr.com/ru/post/1437936/


All Articles