如何使用DynamoDB(NoSQL)建模学生/类 [英] How to model Student/Classes with DynamoDB (NoSQL)
问题描述
我想用DynamoDB和NoSQL取得成功。
I'm trying to get my way with DynamoDB and NoSQL.
对学生表和类表建模的最好的方法是什么事实上,我需要有一个学生是在类的关系。
我考虑到DynamoDB中没有可用的第二索引。
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?
感谢
推荐答案
一个非常简单的建议(没有范围键)会有两个表: 。这在NoSQL数据库中并不罕见。
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:
- 具有属性
StudentId
作为(散列类型)主键的表学生
每个项目可能有一个属性名为Attends
,其值是类上的Id列表。 - c $ c>具有
ClassId
作为(散列类型)主键的类。每个项目可能具有名为AttendedBy
的属性,其值是学生的Id列表。
- 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.
另一个设计会有一个表使用散列和范围主键参加
。每个记录将代表一个学生参加一个班。哈希属性可以是类的Id,范围键可以是学生的Id。关于班级和学生的补充数据将存放在其他表格中。
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屋!