How to retrieve data from DynamoDB via a column other than the Primary ID

Viewed 37

I'm trying to get the data by address on the table.

table

I'm working on Express environment.

Could you help me with how can I get the data by address, not primary ID?

1 Answers

Retrieving data from DynamoDB by using a non-key attribute is not possible. You can define a global secondary index on your address field. Since addresses are not unique, your best bet might be to construct a complex global secondary index consisting of:

  • Partition Key: address
  • Sort Key: ID

That way your global secondary index is unique (because the combination of address and ID is unique) and you can query your global secondary index for a specific address, which will return all records with that address.

Related