0% found this document useful (0 votes)
21 views13 pages

Shah Project

The document defines a data model for a school management system using MongoDB collections. It provides sample documents for collections like school, teacher, student etc. It also lists MongoDB commands for common CRUD operations like insert, find, update and delete on these collections.

Uploaded by

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

Shah Project

The document defines a data model for a school management system using MongoDB collections. It provides sample documents for collections like school, teacher, student etc. It also lists MongoDB commands for common CRUD operations like insert, find, update and delete on these collections.

Uploaded by

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

Project

Name: Shah Zain Reg no: SP22-BAI-044


Name: Jawad Ali Reg no: SP22-BAI-020

SCHOOL Management System


ER And EER:

Data Model: Provide a MongoDB data model, including the structure


of documents for the project.

Collection: school
{"_id": 1,

"name": "School1",

"address": "School Address 1"

}
Collection: teacher

"_id": 1,

"teacher_name": “shah",

"temail": "[email protected]",

"teacher_phone": "123-456-7890",

"dob": "1990-01-01",

"address": "Teacher1 Address",

"school_id": 1

Collection: student

"_id": 1,

"sname": "Student1",

"semail": "[email protected]",

"dob": "2000-01-01",

"address_id": "Student1 Address",

"school_id": 1

Collection: class

"_id": 1,

"cname": "Class1",
"cyear": "2023-01-01",

"school_id": 1

Collection: subject

"_id": 1,

"sname": "Subject1",

"teacher_id": 1

Collection: enrollment

"_id": 1,

"sid": 1,

"cid": 1

Collection: exam

"_id": 1,

"cid": 1,

"Date": "2023-01-01",

"ename": "Exam1"

}
Collection: attendance

"_id": 1,

"sid": 1,

"cid": 1,

"Date": "2023-01-01",

"status": "P"

MongoDB Commands: Write MongoDB commands for the following


operations:
Inserting:

Insert data into the school collection.


db.school.insertOne({
"_id": 1,
"name": "School1",
"address": "School Address 1"
});
Insert data into the teacher collection.
db.teacher.insertOne({
"_id": 1,
"teacher_name": "Teacher1",
"temail": "[email protected]",
"teacher_phone": "123-456-7890",
"dob": "1990-01-01",
"address": "Teacher1 Address",
"school_id": 1
});

Insert data into the student collection.


db.student.insertOne({
"_id": 1,
"sname": "Student1",
"semail": "[email protected]",
"dob": "2000-01-01",
"address_id": "Student1 Address",
"school_id": 1
});
Insert data into the class collection.
db.class.insertOne({
"_id": 1,
"cname": "Class1",
"cyear": "2023-01-01",
"school_id": 1
});

Insert data into the subject collection.


db.subject.insertOne({
"_id": 1,
"sname": "Subject1",
"teacher_id": 1
});
Insert data into the enrollment collection.
db.enrollment.insertOne({
"_id": 1,
"sid": 1,
"cid": 1
});

Insert data into the exam collection.


db.exam.insertOne({
"_id": 1,
"cid": 1,
"Date": "2023-01-01",
"ename": "Exam1"
});
Insert data into the attendance collection.
db.attendance.insertOne({
"_id": 1,
"sid": 1,
"cid": 1,
"Date": "2023-01-01",
"status": "P"});

Querying:
Querying for all documents in a collection:
Find all the documents in the school collection.
db.school.find();

Find all documents in the teacher collection.


db.teacher.find();

Find all the documents in the student collection.


db.student.find();

Find all documents in the class collection.


db.class.find();

Find all documents in the subject collection.


db.subject.find();
Find all documents in the enrollment collection.
db.enrollment.find();

Find all documents in the exam collection.


db.exam.find();

Find all documents in the attendance collection.


db.attendance.find();
Querying with a condition:
Find teachers in School1.
db.teacher.find({ "school_id": 1 });

Find students in School1.


db.student.find({ "school_id": 1 });

Find classes in School1.


db.class.find({ "school_id": 1 });

Find exams for Class1.


db.exam.find({ "cid": 1 });

Find attendance for Student1.


db.attendance.find({ "sid": 1 });
Querying with projection (selecting specific fields):
Find only the names of students in School1.
db.student.find({ "school_id": 1 }, { "sname": 1, "_id": 0 });

Find only the names and emails of teachers.


db.teacher.find({}, { "teacher_name": 1, "temail": 1, "_id": 0 });

Update:

Update a Single Document:


Update the email address for Teacher1.
db.teacher.updateOne({ "teacher_name": "Teacher1" }, { $set: { "temail":
"[email protected]" } });

Update the address for Student1.


db.student.updateOne({ "sname": "Student1" }, { $set: { "address_id": "New Address" } });

Update Multiple Documents:


Update the school’s name for all schools with a specific address.
db.school.updateMany({ "address": "Common Address" }, { $set: { "name": "New School
Name" } });

Update the exam date for all exams in Class1.


db.exam.updateMany({ "cid": 1 }, { $set: { "Date": "2023-02-01" } });

Delete:

Delete a Single Document:


Delete the school with ID 1.
db.school.deleteOne({ "_id": 1 });
Delete the teacher with name "Teacher1".
db.teacher.deleteOne({ "teacher_name": "Teacher1" });
Delete the student with the name "Student1".
db.student.deleteOne({ "sname": "Student1" });

Delete Multiple Documents:


Delete all students in School1.
db.student.deleteMany({ "school_id": 1 });
Delete all exams in Class1.
db.exam.deleteMany({ "cid": 1 });

Delete by Criteria:
Delete all enrollment records for Student1.
db.enrollment.deleteMany({ "sid": 1 });
Delete all attendance records for a specific date.
db.attendance.deleteMany({ "Date": "2023-01-01" });

You might also like