Mongodb Certified Developer Associate C100dev · Free Practice Question Medium

Question 8

You are designing a MongoDB database for a university system. You have the following collections:

  1. Students: Stores information about each student, including their studentId, name, email, and address.

  2. Courses: Stores information about each course, including the courseId, courseName, department, and credits.

  3. Enrollments: Stores the enrollments for each course, with fields studentId, courseId, and enrollmentDate.


In this scenario, each student can enroll in multiple courses, and each course can have multiple students enrolled. However, each enrollment also needs to track the grade and semester for that specific course for the student. Which of the following is the most appropriate data modeling approach for this scenario?

  • A

    Use references in the Enrollments collection to both Students and Courses.

  • B

    Embed the Students data within each Course document.

  • C

    Embed the Enrollments data within each Student document.

  • D

    Create a separate collection for each Semester, with embedded Enrollments for each course and student combination.

Reveal correct answer

Correct answer: A

A.

Using references in the Enrollments collection to both Students and Courses is the most appropriate approach for this scenario. This allows you to efficiently store and retrieve information about enrollments, including course-specific details like grade and semester. It avoids redundancy and enables straightforward queries to find all students enrolled in a particular course or all courses a student is enrolled in.

B.

This approach would lead to significant redundancy, as the same student information would need to be embedded in every course they enroll in. Additionally, if a student's information changes (e.g., address), it would need to be updated in multiple places, leading to data consistency issues.

C.

While embedding enrollments within the student document would allow easy access to all courses a student is enrolled in, this approach is inefficient. Since each course can have many students, this would result in duplication of data if you want to access course-specific information. Additionally, querying all students enrolled in a particular course would be challenging and require scanning through all students.

D.

Creating separate collections for each semester and embedding enrollments within those would complicate the data model and query logic. While it might seem logical to separate data by semester, this approach would result in difficulties when querying across multiple semesters or when retrieving all courses for a particular student, leading to an overly complex structure.

Discussion

Think the marked answer is wrong, or have a better explanation? Share it below — comments appear after review.

You must be logged in to post a comment.

Preparing For

Your Certification?

255+ certifications
Detailed explanations
Free PDF samples

Has All The Questions You Need