How to model Student/Classes with DynamoDB (NoSQL)

前端 未结 2 766
南旧
南旧 2021-02-04 03:51

I\'m trying to get my way with DynamoDB and NoSQL.

What is the best (right?) approach for modeling a student table and class tables with respect to the fact that I need

2条回答
  •  陌清茗
    陌清茗 (楼主)
    2021-02-04 03:57

    A very simple suggestion (without range keys) would be to have two tables: One per query type. This is not unusual in NoSQL databases.

    In your case we'd have:

    • A table Student with attribute StudentId as (hash type) primary key. Each item might then have an attribute named Attends, the value of which was a list of Ids on classes.
    • A table Class with attribute ClassId as (hash type) primary key. Each item might then have an attribute named AttendedBy, the value of which was a list of Ids on students.

    Performing your queries would be simple. Updating the database with one "attends"-relationship between a student and a class requires two separate writes, one to each table.

    Another design would have one table Attends with a hash and range primary key. Each record would represent the attendance of one student to one class. The hash attribute could be the Id of the class and the range key could be the Id of the student. Supplementary data on the class and the student would reside in other tables, then.

提交回复
热议问题