Jackson Mikle
Jackson Mikle

Reputation: 21

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

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?

Upvotes: 2

Views: 100

Answers (1)

Tobias Geiselmann
Tobias Geiselmann

Reputation: 2476

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.

Upvotes: 3

Related Questions