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 to have a student-is-in-class relationship. I'm taking into account that there is no second-index available in DynamoDB.
The model needs to answer the following questions:
Which students are in a specific class?
Which classes a student take?
Thanks
Amazon DynamoDB is a fully managed, serverless, key-value NoSQL database designed to run high-performance applications at any scale. DynamoDB offers built-in security, continuous backups, automated multi-Region replication, in-memory caching, and data import and export tools.
A relational database management system (RDBMS) requires you to define the table's schema when you create it. In contrast, DynamoDB tables are schemaless—other than the primary key, you do not need to define any extra attributes or data types when you create a table.
DynamoDB supports both key-value and document data models. This enables DynamoDB to have a flexible schema, so each row can have any number of columns at any point in time.
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:
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.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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With