I bumped into a question regarding the schema for MongoDB. With reference to the example on MongoDB Schema Design, regarding the db.students and db.courses.
As I am more used to SQL structured, I am still confused with this reference or embed problem. So, the example is only showing the course within the db.students
, is referenced to the db.courses
. So if I were to categorize my courses such as humanities
, languages
, etc, how should I do it?
What would be a better way to do it?
-
1. create a collection called `db.categories` and reference the db.courses to it?
// db.courses
{ name: Biology, cat: 1 }
{ name: English, cat: 2 }
// db.categories
{ cat: 1, name: Humanities }
{ cat: 2, name: Languages }
-
2. to just embed within the courses?
// db.courses
{ name: Biology, cat: Humanities }
{ name: English, cat: Languages }
{ name: History, cat: Humanities }
Could anyone please kindly advise, what should I be doing?
Thank you.