views:

309

answers:

4

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
A: 

In a pure OODB, your model is fine.

S.Lott
Why would I need an ORM? If I'm using something like mongo what comes out is an object already, isn't it?
stimms
Nowhere, but it is an object database not a relational database so using an Object Relational Mapper makes no sense. There is no relational database to map.
stimms
A: 

Have a look at DatabaseAnswers to see if they have an existing schema that meets your needs.

Mitch Wheat
A: 

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.

bmargulies
+2  A: 

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 definite 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.

Alan