简体   繁体   中英

One-to-many relation in DynamoDB

I want to know what is the best approach to works with one-to-many relations in DynamoDB . Let's assume that I have a post and category tables. The category table has id and name columns. The post table has id , title , and category_id columns. With a relational database, I would use join between the two tables. I know that I can't join two tables in DynamoDB. When I present several articles summaries with the category in a page, I know that with a RDBMS I don't need to run a query each time I want to fetch the category name.

I've seen many examples where the category name is embedded as the name and not the ID, so I can just read the document, and I have all the information with a single query. The problem is that when I want to change the category name with DynamoDB I need to run a scan query to update the column—I don't want to do that. I thought about using category_id and use caching in order to not repeating the category name query when paginating. Any good modeling technique how to solve this issue with DynamoDB?

Generally the way people handle joins with NoSQL databases is to duplicate data so that you can query data and have all the required data available.

If your category list is fairly small (10-1000 records) you could just store the category id in the posts table and in code cache the names of the categories and convert and "append" the category name in code when it finds a specific category id.

NoSQL data modeling is a very different beast compared to SQL databases. Generally you want your data to be "flat" so you can query and have all the data in a single request/query.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM