Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Query on non-key attribute

Tags:

It appears that dynamodb's query method must include the partition key as part of the filter. How can a query be performed if you do not know the partition key?

For example, you have a User table with the attribute userid set as the partition key. Now we want to look up a user by their phone number. Is it possible to perform the query without the partition key? Using the scan method, this goal can be achieved, but at the expense of pulling every item from the table before the filter is applied, as far as I know.

like image 913
KJ Price Avatar asked Apr 11 '17 18:04

KJ Price


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 you query on sort key DynamoDB?

You can Query any table or secondary index, provided that it has a composite primary key (partition key and sort key). Query operations consume read capacity units, as follows. The table's provisioned read capacity. The index's provisioned read capacity.

What is Expressionattributevalues?

Expression attribute values in Amazon DynamoDB are substitutes for the actual values that you want to compare—values that you might not know until runtime. An expression attribute value must begin with a colon ( : ) and be followed by one or more alphanumeric characters.


Video Answer


1 Answers

You'll need to set up a global secondary index (GSI), using your phoneNumber column as the index hash key.

You can create a GSI by calling UpdateTable.

Once you create the index, you'll be able to call Query with your IndexName, to pull user records based on the phone number.

like image 156
Unsigned Avatar answered Sep 22 '22 19:09

Unsigned