Recall & Review
beginner
What is a many-to-many relationship in databases?
A many-to-many relationship means that multiple records in one collection can relate to multiple records in another collection. For example, many students can enroll in many courses.
Click to reveal answer
beginner
How do MongoDB references help model many-to-many relationships?
MongoDB uses references by storing the IDs of related documents in arrays. This way, documents can point to many others without duplicating data.
Click to reveal answer
intermediate
Why use references instead of embedding for many-to-many relationships?
References avoid data duplication and keep documents smaller. Embedding many related documents can make documents too large and harder to update.
Click to reveal answer
beginner
Example: How to store course IDs in a student document for many-to-many?
In the student document, include a field like
enrolledCourses which is an array of course IDs. Each ID references a course document.Click to reveal answer
intermediate
What is a common pattern to query many-to-many references in MongoDB?
First, find the document with the array of IDs, then use those IDs to query the related collection. This is called manual referencing or client-side join.
Click to reveal answer
In MongoDB, how do you represent a many-to-many relationship?
✗ Incorrect
MongoDB uses arrays of referenced IDs in documents to represent many-to-many relationships.
Why might embedding not be ideal for many-to-many relationships?
✗ Incorrect
Embedding duplicates data and can cause large documents, which is not efficient for many-to-many.
What field type is commonly used to store references in MongoDB?
✗ Incorrect
References are stored as arrays of ObjectIds pointing to related documents.
How do you retrieve related documents in a many-to-many setup in MongoDB?
✗ Incorrect
You query the array of IDs and then fetch related documents in separate queries.
Which of the following is NOT a benefit of using references for many-to-many?
✗ Incorrect
MongoDB does not automatically enforce foreign key constraints with references.
Explain how to model a many-to-many relationship using references in MongoDB.
Think about how two collections can point to each other using IDs.
You got /4 concepts.
Describe the steps to query related documents in a many-to-many relationship with references in MongoDB.
Remember MongoDB does not do automatic joins like SQL.
You got /4 concepts.