Rajan Soni Rajan Soni - 1 year ago 354
Node.js Question

AWS Dynamodb: Is it possible to make a query only using sort key

enter image description here

Hi dynamodb community,

So the table in question is MLA_USER_AUTH. As you see it has as partition key and as sort key. I want to be able to query the database using both user_id and email.

Sometimes I need to find the user associated with the email and sometimes the userid. Both email and userid attributes are unique for every visitor. is there any way it can be done?

This is my current query. This obviously doesnt work. As it throws the error: ValidationException: Query condition missed key schema element: UserID

var params = {
TableName : 'MLA_USER_AUTH',
KeyConditionExpression: "Email = :email",
":email": { "S" : email }
dynamodb.query(params, function(err, data) {

Are GSIs my only option. Any help appreciated


Answer Source

As Mark B said, you need partition-key to query- you can't do it using sort-key alone.

So, the only way out for you is to create a GSI with email as the partition-key.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download