Skip to content

database

noyamirai edited this page Apr 5, 2022 · 2 revisions

Database structure (Mongoose): Maijla Ikiz ๐Ÿ’พ

For our CMD Online, that creates well balanced teams based on skills of students, we need to be able to store several kinds of data into a database. The database we will be using during this project is called MongoDB.

MongoDB is a document database with the scalability and flexibility that you want with the querying and indexing that you need - MongoDB

MongoDB is a free to use, document-oriented NoSQL database that stores data in JSON-like documents. This means the fields inside a document can vary and the overal data structure can be changed whenever. Instead of using tables and rows, it makes use of collections and documents.

Because MongoDB is not a traditional relational database, it does not have a schema defined beforehand. This means it does not matter how you create your documents and which attributes you put into them.

Models ๐Ÿ“‚

For the CMD Online I found it important that the database had some kind of structure to it. But since MongoDB has a flexible schema and does not enforce a certain document structure, I installed Mongoose.

Mongoose is a schema-based solution that helps you model your database and basically define what fields a document requires before it gets added into a collection.

With the help of Mongoose, I was able to create the following data structure for my matching application:

Team Creator DB Schema

As you can see in the image above, I created several link collections. These link collections help me, for example, find which course a teacher gives and which classes are connected to said course. In order to create these link collections, Mongoose needs reference ids. Once reference ids have been added to a link collection, the Mongoose functionality called populate() is used to get data from the collection and document the reference id is referring to.

The populate() functionality is similar to a left outer join in SQL:

SELECT CompanyName, ProductName
  FROM Supplier S
  LEFT JOIN Product P ON S.Id = P.SupplierId