So I need to design NoSQL Schemas (Mongoose) from next SQL Database.
Image of SQL database
So I have a few questions about how to make those Schemas:
In Mongo, like in SQL, there are many ways you can structure your data. The key to consider in Mongo, is how do you need to access the data. Try to group data in ways that it matches queries you expect to perform. Using that context, I'll try to answer some of your specific questions:
1) Your asking where to store the entryDate of a student into a class. Do you often pull students independently? Or do you always grab them with their classes? Do you need classes independently?
One option would be to nest classes inside of your students: Student =>
{
firstName: "John",
lastName: "Smith",
classes: [{
classCode: "EN101",
entryDate: "10/10/2017"
}]
}
You could also have a class object with a list of students if you access it all it once usually: Class =>
{
classCode: "En101"
students: [{
studentId: 12345,
firstName: "John",
lastName: "Smith,
entryDate: "10/10/2017"
}]
}
If you often reference things separately, you could have a flat table like in your SQL that just has classCode, studentId, studentEntryDate
These objects are all stored together in one table? If so that sounds like a great use of discriminators. like if you just have a People collection. However, I would guess that they are stored separately? Teachers and Students are stored in different collections? In that case you can just have them inherit the same class in code, and they will serialize fine into mongo without any discriminators.
There's multiple ways to handle this. You could create collections for each table and maintain a linking table, but not usually the best way. I would think Teachers and Courses would be one-many not many-many? So each course would have a teacher. If courses do have many teachers, you can just have a list of teachers instead of a field called teacher.
Hope my answers are clear, feel free to comment for more information.
If your pretty new in Mongo, I recommend signing up for some of there free courses. There pretty useful and get you a good foundation.
Good luck on your switch to mongo. It's worth it!