Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can one make a relational database using MongoDB?

I am going to make a student management system using MongoDB. I will have one table for students and another for attendance records. Can I have a key in the attendance table to reach the students table, as pictured below? How?

diagram of a relational database

like image 798
İlker Dağlı Avatar asked Nov 14 '11 23:11

İlker Dağlı


People also ask

Can MongoDB replace RDBMS?

MongoDB is almost 100 times faster than traditional database system like RDBMS which is slower in comparison with the NoSQL databases. There is no support for complex joins in MongoDB but RDBMS supports complex joins which can be difficult to understand and take too much time to execute.

Is MongoDB relational or NoSQL?

MongoDB is a database based on a non-relational document model. Thus, as a so-called NoSQL database (NoSQL = Not-only-SQL), it differs fundamentally from conventional relational databases such as Oracle, MySQL or the Microsoft SQL Server.

Why MongoDB is non-relational?

Non-relational database for JSON-like documents MongoDB is a non-relational document database that provides support for JSON-like storage. The MongoDB database has a flexible data model that enables you to store unstructured data, and it provides full indexing support, and replication with rich and intuitive APIs.


2 Answers

The idea behind MongoDB is to eliminate (or at least minimize) relational data. Have you considered just embedding the attendance data directly into each student record? This is actually the preferred design pattern for MongoDB and can result in much better performance and scalability.

If you truly need highly relational and normalized data, you might want to reconsider using MongoDB.

like image 114
Mike Christensen Avatar answered Sep 25 '22 02:09

Mike Christensen


The answer depends on how you intend to use the data. You really have 2 options, embed the attendance table, or link it. More on these approaches is detailed here: http://www.mongodb.org/display/DOCS/Schema+Design

For the common use-case, you would probably embed this particular collection, so each student record would have an embedded "attendance" table. This would work because attendance records are unlikely to be shared between students, and retrieving the attendance data is likely to require the student information as well. Retrieving the attendance data would be as simple as:

db.student.find( { login : "sean" } ) {   login : "sean",   first : "Sean",    last : "Hodges",   attendance : [     { class : "Maths", when : Date("2011-09-19T04:00:10.112Z") },     { class : "Science", when : Date("2011-09-20T14:36:06.958Z") }   ] } 
like image 45
seanhodges Avatar answered Sep 27 '22 02:09

seanhodges