设计文档数据库架构

发布于 2024-08-22 22:19:39 字数 505 浏览 3 评论 0原文

我徒劳地尝试学习如何使用对象数据库。在数据库教科书中,传统似乎是使用跟踪学生、课程和班级的例子,因为它是如此熟悉和适用。作为对象数据库,这个示例会是什么样子?关系数据库看起来像

Student
  ID
  Name
  Address

Course
  ID
  Name
  PassingGrade

Class
  ID
  CourseID
  Name
  StartTime

StudentClass
  ID
  ClassID
  StudentID
  Grade

你是否将 StudentClasses 保留在 Classes 中,而 Classes 又保留在 Course 中,然后将 Student 作为顶级实体?

Student
  ID
  Name
  Address

Course
  ID
  Name
  Classes[]
    Name
    StartTime
    Students[]
      StudentID

I'm vainly attempting to learn how to use object databases. In database textbooks the tradition seems to be to use the example of keeping track of students, courses and classes because it is so familiar and applicable. What would this example look like as an object database? The relational database would look something like

Student
  ID
  Name
  Address

Course
  ID
  Name
  PassingGrade

Class
  ID
  CourseID
  Name
  StartTime

StudentClass
  ID
  ClassID
  StudentID
  Grade

Would you keep StudentClasses inside of Classes which is, in turn, inside Course and then keep Student as a top level entity?

Student
  ID
  Name
  Address

Course
  ID
  Name
  Classes[]
    Name
    StartTime
    Students[]
      StudentID

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

油饼 2024-08-29 22:19:39

因此,您有 CourseStudentClass,它们是 Course 的一部分,并由 访问代码>学生?我想,如果你仔细想想,这个问题本身就会有答案。如果您放弃 MongoDB 的纯 JSON,并看看如何在 ODM(相当于 RDB 中的 ORM)中定义它,也许会更清楚,因为基于文档的 DB 并不真正强制执行自己的模式(示例基于on MongoEngine for Python):

class Student(Document):
    name = StringField(max_length=50)
    address = StringField()

class Attendance(EmbeddedDocument):
    student = ReferenceField(Student)
    grade = IntField(min_value=0, max_value=100)

class Class(EmbeddedDocument):
    name = StringField(max_length=100)
    start_time = DateTimeField()
    attendance_list = ListField(EmbeddedDocumentField(Attendance))

class Course(Document):
    name = StringField(max_length=100)
    classes = ListField(EmbeddedDocumentField(Class))

这将为您提供两个集合:一个用于 Student ,另一个用于 Course出勤将嵌入到Class中,而Class将嵌入到课程中。像这样的东西(伪代码):

Student = {
    name: String,
    address: String
}

Course = {
    name: String,
    classes: {
        name: String,
        start_time: DateTime,
        attendance_list: {
            student: Student,
            grade: Integer
        }[]
    }[]
 }

您当然可以将成绩信息放入学生对象中,但最终您实际上无法做太多事情来摆脱那个额外的班级。

So you have Courses, Students and Classes, which are parts of Courses and visited by Students? I think the question answers itself if you think about it. Maybe it's clearer if you go away from the pure JSON of MongoDB and look at how you would define it in an ODM (the equivalent of an ORM in RDBs) as document based DBs don't really enforce schemas of their own (example is based on MongoEngine for Python):

class Student(Document):
    name = StringField(max_length=50)
    address = StringField()

class Attendance(EmbeddedDocument):
    student = ReferenceField(Student)
    grade = IntField(min_value=0, max_value=100)

class Class(EmbeddedDocument):
    name = StringField(max_length=100)
    start_time = DateTimeField()
    attendance_list = ListField(EmbeddedDocumentField(Attendance))

class Course(Document):
    name = StringField(max_length=100)
    classes = ListField(EmbeddedDocumentField(Class))

This would give you two collections: one for Students and one for Courses. Attendance would be embedded in the Classes and the Classes would be embedded in the Courses. Something like this (pseudocode):

Student = {
    name: String,
    address: String
}

Course = {
    name: String,
    classes: {
        name: String,
        start_time: DateTime,
        attendance_list: {
            student: Student,
            grade: Integer
        }[]
    }[]
 }

You could of course put the grade info in the student object, but ultimately there really isn't much you can do to get rid of that extra class.

小忆控 2024-08-29 22:19:39

OODBMS 的全部意义在于允许您设计数据模型,就好像它只是在内存中一样。不要将其视为数据库模式问题,而应将其视为数据建模问题,假设您拥有大量虚拟机和有限数量的物理内存,您要确保没有沸腾大量页面错误(或者实际上是数据库 I/O 操作)来执行重要的操作。

The whole point of an OODBMS is to allow you to design your data model as if it were just in memory. Don't think of it as a database schema problem, think of it as a data modelling problem on the assumption that you have a whole lot of VM and a finite amount of physical memory, You want to make sure that you don't have to boil an ocean of page faults (or, in fact, database I/O operations) to do the operations that are important.

阿楠 2024-08-29 22:19:39

在纯 OODB 中,您的模型很好。

In a pure OODB, your model is fine.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文