Hello @John_D1, welcome to the MongoDB Community forum!
I have some information for you and hope it is useful. I will assume there are a few thousand students and few hundred courses, and I could model something like this:
student:
{
_id: <number>,
name: : <string>,
otherDetails: { ... },
courses: [
{ courseId: <number>, courseName: <string> },
{ courseId: <number>, courseName: <string> },
...
]
}
course:
{
_id: <number>,
name: <string>,
description: <string>,
otherDetails: { ... }
}
Now, your application has some queries. To start with some queries I can think about is, get all students in a particular course and get all courses for a particular student. These are simple queries.
To get all courses for a specific student, the query would be:
db.students.find( { name: "John Doe" }, { courses: 1, name: 1 } )
To get all students enrolled for a specific course, your query can be like this:
db.students.find( { "courses.courseName": "Database Design" } )
Note that the data related to the course is duplicated - the course name and id are present in both collections. You can also note that these details will not change often (or may not change at all). This is feasible, though you have the same data in both collections. And, this also makes querying simpler.
Some important aspects that influence database design are the amount of data in each entity, the size of each document, the relationships between entities, the application functionality (note that all this is part of an app, and the app has various functions, like displaying certain data in browser window, for example), and the other queries you write for the application (the CRUD operations).
The “linked table” is not needed in the MongoDB data design - which allows denormalized data through embedding or referencing. Based upon the kind of queries you write you can have the course referenced within the student or vice-versa.
In the above student entity, the courses field is an array of { courseId: <number>, courseName: <string> } embedded documents. You can also include more course details in this embedded document, or just the courseId field. If you have just the courseId in the courses array field, then you will have to use an Aggregation Query with $lookup to get more details about the courses.