abrarcv170
abrarcv170

Reputation: 37

How to store and retrieve one to many relationship data in AWS dynamodb

{
"vendor_id": "jack123xx",
  "book_list": [
    {
      "category": "crime",
       "price" : "100$",
      "book_id": "1234A",
      "name": "human_body"
    },
    {
      "category": "romantic",
      "book_id": "1234B",
      "name": "trash",
      "price" : "121$",
    }
  ]
}

i want to store the above data in a dynamodb table,frequently retrieve and update the price of books based on book_id and vendor_id ,which is the best way to organise these data in aws dynamodb.

Upvotes: 0

Views: 89

Answers (1)

Libu Mathew
Libu Mathew

Reputation: 2996

You can use vendor_id as the PartitionKey and book_id as the SortKey.

Using this approach you achieve all of your requirements like:

  • Fetch all books based on vendor_id
  • Update/delete book details based on vender_id and book_id

Also check DynamoDB LSI and GSI features that will help you to accommodating future requirements.

Upvotes: 2

Related Questions