如何使用 DynamoDB (NoSQL) 为学生/班级建模 [英] How to model Student/Classes with DynamoDB (NoSQL)
问题描述
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
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 attributeStudentId
as (hash type) primary key. Each item might then have an attribute namedAttends
, the value of which was a list of Ids on classes. - A table
Class
with attributeClassId
as (hash type) primary key. Each item might then have an attribute namedAttendedBy
, 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.
这篇关于如何使用 DynamoDB (NoSQL) 为学生/班级建模的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!