Reputation: 8374
I am modeling a simple application an I would like to use DynamoDB as my storage. I need to store a all order from a ecommerce website. It is possible to query using the order_id and the user email.
Looking at the dynamodb documentation, I think the best approach is to user the order_id (Most of my queries will be made on this index) as my primary key (Partition key).
And what about email? I would like a secondary index, but I am bit lost. What is the best approach?
Upvotes: 0
Views: 588
Reputation: 37832
It looks like a Global Secondary Index on the email
attribute would solve the problem:
when you need to lookup by order_id
, you use the GetItem
operation and specify that order_id
as the primary key
when you need to lookup by email
, you use the Query
API on the GSI and specify the email
as the partition key.
GSI have independent read capacity units - since you said you will use order_id most of the time, you could provision more RCU to the main table than the GSI.
Reference:
Upvotes: 0