๐งพ MongoDB Document Modeling – Practice Assignment
Title: Design a NoSQL Document Structure for a School Management System
Level: Beginner to Intermediate
Objective: Learn how to organize and model data using MongoDB’s document structure.
๐ Assignment Brief
You are designing a database for a School Management System using MongoDB. Your task is to model documents for students, courses, and marks using a proper JSON-like structure.
You need to:
๐น 1. Create a students
collection
Each student document should include:
-
student_id
(Number) -
name
(String) -
class
(String) -
date_of_birth
(ISO Date format) -
contact_info
(Nested object with phone and email)
๐น 2. Create a courses
collection
Each course document should include:
-
course_id
(Number) -
title
(String) -
teacher_name
(String) -
schedule
(Array of days, e.g., ["Mon", "Wed", "Fri"])
๐น 3. Embed marks
within each student document
Instead of a separate marks
collection, embed a list of subjects and scores within the student document like this:
"marks": [
{ "subject": "Math", "score": 85 },
{ "subject": "Science", "score": 90 }
]
๐ง Optional Bonus Task
Write a MongoDB query to:
-
Find students who scored above 80 in Math
-
Project only the student's name and Math score
๐งช Expected Sample Document (students collection)
{
"student_id": 101,
"name": "Aisha Khan",
"class": "10A",
"date_of_birth": "2008-05-10T00:00:00Z",
"contact_info": {
"phone": "9876543210",
"email": "aisha.khan@example.com"
},
"marks": [
{ "subject": "Math", "score": 85 },
{ "subject": "Science", "score": 90 }
]
}
๐ง Why This Matters
-
Reinforces document structure and nesting in MongoDB
-
Helps students understand when to embed vs reference
-
Mirrors real-world use cases like student performance tracking
solution :
No comments:
Post a Comment