0% found this document useful (0 votes)
26 views20 pages

Niit Campus Technology LTD

Uploaded by

Abdulsamad
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
26 views20 pages

Niit Campus Technology LTD

Uploaded by

Abdulsamad
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 20

NIIT CAMPUS TECHNOLOGY LMD.

NAME: AJAYI ABDUL-SAMAD AYOMIDE


PROJECT TITLE: SCHOOL DATABASE
COURSE: MMS-SE
COURSE-SUBJ: MONGODB
DATE: 11/27/2024
SUBTITLE: MONGODB PROJECT
Table of Contents
1. Introduction.............................................................................................................................................4
 Overview of the Project:......................................................................................................................4
 Objectives and Purpose:.......................................................................................................................4
 Project Goals:.......................................................................................................................................4
2.Database Structure...................................................................................................................................4
 Collections Overview:...........................................................................................................................4
Students Collection:.............................................................................................................................5
Teachers Collection:.............................................................................................................................6
Courses Collection:..............................................................................................................................7
3. Relationships Between Collections..........................................................................................................8
1. Student to Courses:.............................................................................................................................8
2. Teacher to Courses:.............................................................................................................................9
3. Course to Students:.............................................................................................................................9
4.CRUD Operations......................................................................................................................................9
1. Create Operation (Insert Data)............................................................................................................9
2. Read Operation (Retrieve Data).........................................................................................................11
3. Update Operation (Modify Data).......................................................................................................12
4. Delete Operation (Remove Data).......................................................................................................13
5. Database Schema Design Diagram.........................................................................................................14
6. How to Use the Database: A Step-by-Step Guide..................................................................................15
1. Setting Up the Database:...................................................................................................................15
2. Adding Data to the Collections (Create Operation)............................................................................16
3. the Collections (Read Operation). Retrieving Data from....................................................................17
4. Updating Data in the Collections (Update Operation).......................................................................18
5. Deleting Data from the Collections (Delete Operation).....................................................................18
6. Querying Complex Data.....................................................................................................................18
7. Exporting and Importing Data............................................................................................................19
8. Indexing for Faster Queries................................................................................................................19
9. Data Backup and Restoration.............................................................................................................19
Backup the Database.........................................................................................................................19
Restore the Database........................................................................................................................19
10. Best Practices for Database Use.......................................................................................................20
1. Data Validation:.............................................................................................................................20
2. Indexes...........................................................................................................................................20
3. Data Backup:..................................................................................................................................20
4. Access Control................................................................................................................................20
7. Future Enhancements............................................................................................................................20
1. Admin Panel.......................................................................................................................................20
2. Authentication...................................................................................................................................20
3. Reporting:..........................................................................................................................................20
8. Conclusion.............................................................................................................................................20
1. Introduction

 Overview of the Project:


The School Database project is designed to manage and organize key academic data efficiently using
MongoDB, a NoSQL database. It includes three main collections: Students, Teachers, and Courses. Each
collection contains detailed information and is interconnected through unique identifiers (ObjectId),
forming a robust data model suitable for educational institutions.

 Objectives and Purpose:


1. Efficient Data Management: To provide a structured way to store and manage data related to
students, teachers, and courses.

2. Interconnected Data: Establish relationships between collections for dynamic data retrieval, enabling
queries like “Which students are enrolled in a particular course?” or “Which courses does a specific
teacher instruct?”

3. Scalability: Use MongoDB’s document model to handle large volumes of data, ensuring flexibility and
scalability.

4. User Interaction: Support administrative tasks such as viewing, adding, or modifying data related to
students, teachers, and courses.

 Project Goals:
 Store detailed data for each student, teacher, and course.
 Establish and demonstrate relationships between collections using ObjectId references.
 Provide examples of CRUD (Create, Read, Update, Delete) operations to manipulate the data
effectively.
 Document and present the project in a way that showcases its functionality and potential
applications.

2.Database Structure

 Collections Overview:

The database consists of three primary collections:

1. Students Collection:

Stores detailed information about students, including personal details, contact information, enrolled
courses, and academic performance.
2. Teachers Collection:

Contains information about teachers, including their subjects, experience, contact details, and the
courses they teach.

3. Courses Collection:

Includes course details such as the course name, description, credits, and the students enrolled.

Students Collection:

Here is the structure of a typical student document:

"_id": { "$oid": "60c72b2f4f1a4e3d88f7e5f1" },

"name": "Alice Johnson",

"age": 15,

"sex": "Female",

"class": "10th Grade",

"courses": [

{ "$oid": "60c72c4e4f1a4e3d88f7e702" },

{ "$oid": "60c72c4e4f1a4e3d88f7e704" }

],

"email": "alicejohnson@gmail.com",

"address": "No 23, Aco Estate, Main-de Street, Abuja.",

"phone": "08151234091",

"gpa": 3.5,

"guardianName": "Emma Johnson",

"enrollmentDate": "2024-01-01"

Fields Explanation:

_id: Unique identifier for each student.


name: Full name of the student.

age: Age of the student.

sex: Gender of the student.

class: Current grade or class level.

courses: Array of course ObjectId references to link with the Courses collection.

email: Contact email address.

address: Residential address.

phone: Contact phone number.

gpa: Grade Point Average, indicating academic performance.

guardianName: Name of the student's guardian.

enrollmentDate: Date the student enrolled.

Teachers Collection:

Example teacher document structure:

"_id": { "$oid": "60c72b3f4f1a4e3d88f7e701" },

"title": "Mr.",

"name": "William Carter",

"age": 40,

"gender": "Male",

"subject": "Mathematics",

"courses": [

{ "$oid": "60c72c4e4f1a4e3d88f7e701" },

{ "$oid": "60c72c4e4f1a4e3d88f7e718" }

],

"email": "williamcarter@gmail.com",

"address": "No 12, Gwarinpa Estate, 3rd Avenue, Abuja.",

"phone": "09154010923",
"yearsOfExperience": 15,

"salary": 55000,

"hiredDate": "2023-06-21"

Fields Explanation:

_id: Unique identifier for each teacher.

title: Salutation (Mr., Ms., Dr., etc.).

name: Full name of the teacher.

age: Age of the teacher.

gender: Gender of the teacher.

subject: Main subject taught by the teacher.

courses: Array of course ObjectId references linking to the Courses collection.

email: Contact email address.

address: Residential address.

phone: Contact phone number.

yearsOfExperience: Total teaching experience in years.

salary: Monthly salary of the teacher.

hiredDate: Date when the teacher was hired.

Courses Collection:

Example course document structure:

"_id": { "$oid": "60c72c4e4f1a4e3d88f7e700" },

"name": "Introduction to Biology",

"description": "An overview of basic biological principles.",

"credits": 3,

"department": "Science",
"teacherId": [

{ "$oid": "60c72b3f4f1a4e3d88f7e702" },

{ "$oid": "60c72b3f4f1a4e3d88f7e707" }

],

"semester": "2nd Semester 2024",

"studentsEnrolled": [

{ "$oid": "60c72b2f4f1a4e3d88f7e5f2" },

{ "$oid": "60c72b2f4f1a4e3d88f7e604" }

Fields Explanation:

_id: Unique identifier for each course.

name: Name of the course.

description: Brief overview of the course.

credits: Credit value of the course.

department: Department offering the course (e.g., Science, Arts).

teacherId: Array of ObjectId references to teachers teaching the course.

semester: Semester in which the course is offered.

studentsEnrolled: Array of ObjectId references to enrolled students.

3. Relationships Between Collections

In this database, the collections are related to each other using ObjectIds. This creates references
between documents in different collections. The relationships are as follows:

1. Student to Courses:
Each student can be enrolled in multiple courses. This relationship is established by referencing the
courses collection in the students collection. The courses field in a student document contains an array
of ObjectIds, each representing a course the student is enrolled in.

2. Teacher to Courses:

Each teacher can teach multiple courses, and each course can have multiple teachers. The courses field
in the teachers collection contains an array of ObjectIds referencing the courses taught by that teacher.
Similarly, the teacherId field in the courses collection references the teachers who teach that particular
course.

3. Course to Students:

Each course can have multiple students enrolled. This relationship is established by referencing the
students collection in the courses collection. The studentsEnrolled field in a course document contains
an array of ObjectIds referencing the students who are enrolled in the course.

4.CRUD Operations

In this section, we'll discuss the basic CRUD (Create, Read, Update, Delete) operations for interacting
with the MongoDB database. These operations are fundamental for managing data in our school
management system.

1. Create Operation (Insert Data)


To add new records to the database, we use the insertOne() and insertMany() methods for inserting a
single document or multiple documents, respectively.

Inserting a New Student:

db.students.insertOne({

"name": "John Doe",

"age": 16,

"sex": "Male",

"class": "11th Grade",

"courses": [

{ "$oid": "60c72c4e4f1a4e3d88f7e702" },
{ "$oid": "60c72c4e4f1a4e3d88f7e704" }

],

"email": "johndoe@gmail.com",

"address": "No 5, Akwa Street, Lagos.",

"phone": "08033456789",

"gpa": 3.7,

"guardianName": "Jane Doe",

"enrollmentDate": "2024-01-15"

});

Inserting Multiple Teachers:

db.teachers.insertMany([

"title": "Ms.",

"name": "Sarah Williams",

"age": 35,

"gender": "Female",

"subject": "Physics",

"courses": [

{ "$oid": "60c72c4e4f1a4e3d88f7e701" }

],

"email": "sarahwilliams@gmail.com",

"address": "No 4, Sapele Road, Benin.",

"phone": "09122223333",

"yearsOfExperience": 10,

"salary": 50000,

"hiredDate": "2023-05-21"

},
{

"title": "Mr.",

"name": "James Brown",

"age": 50,

"gender": "Male",

"subject": "English Literature",

"courses": [

{ "$oid": "60c72c4e4f1a4e3d88f7e718" }

],

"email": "jamesbrown@gmail.com",

"address": "No 10, Broad Street, Lagos.",

"phone": "09123334444",

"yearsOfExperience": 20,

"salary": 60000,

"hiredDate": "2015-01-09"

]);

2. Read Operation (Retrieve Data)


MongoDB provides methods such as find() to retrieve data from collections. This method allows filtering,
sorting, and projection of specific fields.

Finding a Specific Student:

db.students.find({ "name": "Alice Johnson" });

Finding Students Enrolled in a Specific Course:

db.students.find({ "courses": { "$in": [{ "$oid": "60c72c4e4f1a4e3d88f7e702" }] } });


Finding Teachers Who Teach a Specific Subject:

db.teachers.find({ "subject": "Mathematics" });

Finding Courses Taught by a Specific Teacher:

db.courses.find({ "teacherId": { "$in": [{ "$oid": "60c72b3f4f1a4e3d88f7e701" }] } });

3. Update Operation (Modify Data)

To modify existing documents in MongoDB, we use updateOne(), updateMany(), or replaceOne(). These


methods allow you to update one or more documents that match a specific filter.

Updating a Student’s GPA:

db.students.updateOne(

{ "name": "Alice Johnson" },

{ $set: { "gpa": 3.9 } }

);

Updating a Teacher's Salary:

db.teachers.updateOne(

{ "name": "William Carter" },

{ $set: { "salary": 60000 } }

);

Adding a New Course to a Student’s Enrollment:

db.students.updateOne(
{ "name": "John Doe" },

{ $push: { "courses": { "$oid": "60c72c4e4f1a4e3d88f7e718" } } }

);

Multiple Courses Enrolled by Students:Updating

db.students.updateMany(

{ "class": "10th Grade" },

{ $set: { "gpa": 3.8 } }

);

4. Delete Operation (Remove Data)

To delete documents from a collection, we use deleteOne(), deleteMany(), or drop(). These methods
allow for the removal of specific or all documents.

Deleting a Student Record:

db.students.deleteOne({ "name": "Alice Johnson" });

Deleting a Teacher Record:

db.teachers.deleteOne({ "name": "William Carter" });

Removing a Student from a Course:

db.courses.updateOne(

{ "name": "Introduction to Biology" },

{ $pull: { "studentsEnrolled": { "$oid": "60c72b2f4f1a4e3d88f7e5f1" } } }

);

Deleting All Students from a Specific Grade:


db.students.deleteMany({ "class": "10th Grade" });

Example Query Execution:

Let's say we want to retrieve the list of all students who are enrolled in the "Mathematics" course.

1. Find the course:

db.courses.find({ "name": "Mathematics" });

This will give us the ObjectId of the course.

2. Find all students enrolled in this course:

db.students.find({ "courses": { "$in": [ObjectId("60c72c4e4f1a4e3d88f7e702")] } });

5. Database Schema Design Diagram

This will include the students, teachers, and courses collections, and how they relate to each other.
6. How to Use the Database: A Step-by-Step Guide

This section provides a comprehensive guide on how to interact with the MongoDB School Database
using basic CRUD (Create, Read, Update, Delete) operations. It also explains how to set up, query, and
manage data efficiently.

1. Setting Up the Database:

1. Install MongoDB: Ensure MongoDB is installed on your system. Download and install it from the
official MongoDB website.

2. Start the MongoDB Server: Run the following command in the terminal to start the MongoDB service:

‘mongod’

This starts the MongoDB server on the default port 27017.

3. Connect to MongoDB Compass (GUI option):

Open MongoDB Compass (Graphical User Interface).

Connect to localhost:27017 to access the database locally.

4. Connect via Mongo Shell (CLI option):

Open a new terminal and type:

‘mongo’

This opens the MongoDB shell, where you can run MongoDB commands directly.

5. Create a New Database: To create the school database:

‘use schoolDatabase’
2. Adding Data to the Collections (Create Operation)

Example: Inserting a Student Record

To add a new student, use the following command in the MongoDB shell or in a script:

db.students.insertOne({

name: "John Doe",

age: 16,

sex: "Male",

class: "11th Grade",

courses: [

ObjectId("60c72c4e4f1a4e3d88f7e700"),

ObjectId("60c72c4e4f1a4e3d88f7e704")

],

email: "johndoe@gmail.com",

address: "No 45, Central Street, Abuja.",

phone: "08123456789",

gpa: 3.8,

guardianName: "Sarah Doe",

Enrolled_Date: "15-01-2024"

});

Example: Inserting a Teacher Record

db.teachers.insertOne({

title: "Dr.",

name: "Jane Smith",

age: 42,

gender: "Female",

subject: "Chemistry",

courses: [
ObjectId("60c72c4e4f1a4e3d88f7e701"),

ObjectId("60c72c4e4f1a4e3d88f7e710")

],

email: "janesmith@school.edu",

address: "No 12, Oak Avenue, Abuja.",

phone: "09012345678",

yearsOfExperience: 18,

salary: 60000,

Hired_Date: "05-09-2019"

});

3. the Collections (Read Operation). Retrieving Data from

Example: Retrieve All Students

db.students.find().pretty();

This command fetches all documents in the students collection and displays them in a readable format.

Example: Retrieve a Specific Student by Name

db.students.findOne({ name: "John Doe" });

Example: Retrieve All Courses a Student is Enrolled In

Use an aggregation pipeline to join the students collection with the courses collection:

db.students.aggregate([

{ $match: { name: "John Doe" } },

$lookup: {

from: "courses",

localField: "courses",
foreignField: "_id",

as: "enrolledCourses"

]);

4. Updating Data in the Collections (Update Operation)

Example: Add a New Course to a Student’s Enrollment

db.students.updateOne(

{ name: "John Doe" },

{ $push: { courses: ObjectId("60c72c4e4f1a4e3d88f7e708") } }

);

Example: Update a Teacher’s Salary

db.teachers.updateOne(

{ name: "Jane Smith" },

{ $set: { salary: 65000 } }

);

5. Deleting Data from the Collections (Delete Operation)

Example: Remove a Student

db.students.deleteOne({ name: "John Doe" });

Example: Remove a Course from the Database

db.courses.deleteOne({ name: "Introduction to Biology" });

6. Querying Complex Data


Example: Find All Students Enrolled in a Specific Course

db.students.find({ courses: ObjectId("60c72c4e4f1a4e3d88f7e700") });

Example: Find All Teachers with More Than 10 Years of Experience

db.teachers.find({ yearsOfExperience: { $gt: 10 } });

7. Exporting and Importing Data

Export Data to JSON

To export data from a collection to a JSON file:

mongoexport --db schoolDatabase --collection students --out students.json

Import Data from JSON

To import data into a collection from a JSON file:

mongoimport --db schoolDatabase --collection students --file students.json --jsonArray

8. Indexing for Faster Queries

To improve query performance, create indexes on frequently queried fields.

Example: Create an Index on the name Field in Students Collection

db.students.createIndex({ name: 1 });

9. Data Backup and Restoration

Backup the Database


mongodump --db schoolDatabase --out /backup/schoolDatabase

Restore the Database


mongorestore --db schoolDatabase /backup/schoolDatabase
10. Best Practices for Database Use

1. Data Validation: Ensure all data entered follows the expected format (e.g., valid email
addresses, correct ObjectId references).

2. Indexes: Use indexes on frequently queried fields to improve performance.


3. Data Backup: Regularly back up the database to avoid data loss.
4. Access Control: Use MongoDB's authentication features to restrict access to the database.

7. Future Enhancements

1. Admin Panel: A web-based interface to manage the students, teachers, and courses.
2. Authentication: Implementing a user authentication system for teachers and students.
3. Reporting: Adding functionality to generate reports, such as a student’s GPA, teacher’s salary,
or course enrollment statistics.

8. Conclusion

This MongoDB School Database project is an efficient way to store and manage school data. Using
MongoDB’s flexible document-based structure, it can handle complex data relationships with ease. The
use of references (ObjectIds) allows for efficient querying and maintains the integrity of the data.

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy