Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

AWS DynamoDB Query based on non-primary keys

I'm new to AWS DynamoDB and wanted to clarify something. Is it possible to query a table and filter base on a non-primary key attribute. My table looks like the following

Store Id: PrimaryKey Name: simple string Location: simple string

Now I want to query on the Name, but I think I have to give the key as well from what I know? Apart from that I can use the scan but then I will be loading all the data.

like image 462
tmp dev Avatar asked Nov 27 '17 22:11

tmp dev


People also ask

Can you Query DynamoDB without primary key?

Hash key in DynamoDB The primary reason for that complexity is that you cannot query DynamoDB without the hash key. So, it's not allowed to query the entire database. That means you cannot do what you would call a full table scan in other databases.

Can we Query DynamoDB with only sort key?

You can not query only using a Sort Key. You need to specify a partition key to perform query operations. Else, you need to create a global secondary index or perform a scan operation.

Does Amazon DynamoDB support conditional operations?

Yes, like all the other database management systems, DynamoDB also supports all the conditional operators, User can specify a condition that is satisfied for a put, update, or delete operation to work on an item.

Can DynamoDB handle complex queries?

DynamoDB has many attractive features. For example, it can automatically scale to handle trillions of calls in a 24-hour period. It can be used as a key-value store or a document database, and it can handle complex access patterns much faster than a typical relational database.


1 Answers

From the docs:

The Query operation finds items based on primary key values. You can query any table or secondary index that has a composite primary key (a partition key and a sort key).

DynamoDB requires queries to always use the partition key.

In your case your options are:

  • create a Global Secondary Index that uses Name as a primary key
  • use a Scan + Filter if the table is relatively small, or if you expect the result set will include the majority of the records in the table
like image 128
Mike Dinescu Avatar answered Oct 05 '22 23:10

Mike Dinescu