如何使用 DynamoDB (NoSQL) 为学生/班级建模 [英] How to model Student/Classes with DynamoDB (NoSQL)

查看:15
本文介绍了如何使用 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 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.

这篇关于如何使用 DynamoDB (NoSQL) 为学生/班级建模的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆