简体   繁体   中英

One-to-many relationships in NoSQL DB

I just start to learning DynamoDB and I face a big problem.

Suppose, I have an author and a book table where the author can have multiple books and each book must have an author.

so, In NonSQL DB I just embedded author information in book table to solve this problem.

Sample code: https://pastebin.ubuntu.com/p/DvHpS8JQJV/

But, recently I face a problem which is, if long time later admin want to change some information about author like, live attribute. How can I make effect in book table.

Note: Embedded book collection in author table could solve this problem but in future retrieve all books data with pagination and other operation could be more difficult.

In relational db it's every easy to solve just use foreign key and retrieve data by using join query.

How can I solve this type of problem In NonSQL or dynamoDB any suggestions?

You have two options.

  • Go with semi-sql design. Create separate table for books and autor. And joins will be handled on application level. It's not perfect from performance perspective, but it's easy to start for devs with SQL background.
  • Go with single table design. This is a complex topic. There is no silver bullet to handle one-to-many relationships like in SQL. You need good understanding of your domain and single table design to do this well.

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