Share
Explore

W23 MAD6123 Lab Test 1

MongoDB Lab Test: College Enrollment System

Due: 2 p.m. March 22

Worth 15% of Final Grade
Grading:
50% of your Mark will: Your Database demonstrates correct collections and doucments according to the instructions.
50% of your Mark will be: Instructor’s Evaluation of your Understanding.

Objective:

To create a College Enrollment System using MongoDB and to populate the database with sample data.


For a future activity you will enrollment students into Classes - but not for this Test.


Instructions:
Create a new database called "CollegeEnrollmentSystem".
Create two collections called "students" and "courses".
Populate the "students" collection with 5 documents with the following fields:

Name
Age
Gender
Email
Phone Number
Address
Sample Data:
{
"Name": "John Doe",
"Age": 20,
"Gender": "Male",
"Email": "johndoe@example.com",
"Phone Number": "1234567890",
"Address": "123 Main St, Anytown USA"
},
{
"Name": "Jane Smith",
"Age": 19,
"Gender": "Female",
"Email": "janesmith@example.com",
"Phone Number": "0987654321",
"Address": "456 Elm St, Anytown USA"
},
{
"Name": "Bob Johnson",
"Age": 21,
"Gender": "Male",
"Email": "bobjohnson@example.com",
"Phone Number": "5555555555",
"Address": "789 Oak St, Anytown USA"
},
{
"Name": "Sara Lee",
"Age": 18,
"Gender": "Female",
"Email": "saralee@example.com",
"Phone Number": "7777777777",
"Address": "111 Pine St, Anytown USA"
},
{
"Name": "Tom Smith",
"Age": 22,
"Gender": "Male",
"Email": "tomsmith@example.com",
"Phone Number": "2222222222",
"Address": "222 Maple St, Anytown USA"
}


Populate the "courses" collection with 5 documents with the following fields:

Course Name
Instructor Name
Course Description
Course Duration
Sample Data:
{
"Course Name": "Introduction to Computer Science",
"Instructor Name": "Dr. Jane Doe",
"Course Description": "This course provides an introduction to computer science and programming.",
"Course Duration": "10 weeks"
},
{
"Course Name": "Data Structures and Algorithms",
"Instructor Name": "Dr. John Smith",
"Course Description": "This course covers data structures and algorithms used in computer science.",
"Course Duration": "12 weeks"
},
{
"Course Name": "Database Management Systems",
"Instructor Name": "Dr. Bob Johnson",
"Course Description": "This course covers database management systems.",
"Course Duration": "8 weeks"
},
{
"Course Name": "Web Development",
"Instructor Name": "Dr. Sara Lee",
"Course Description": "This course covers web development technologies such as HTML, CSS, and JavaScript.",
"Course Duration": "10 weeks"
},
{
"Course Name": "Artificial Intelligence",
"Instructor Name": "Dr. Tom Smith",
"Course Description": "This course covers artificial intelligence and machine learning.",
"Course Duration": "12 weeks"
}


Submission:

Submit a Word Document with screenshots of the populated "students" and "courses" collections along with the code used to populate the database.
Save your Word Document as student_name-StudentID.docx

Upload to:


Solution:

Here are the MongoDB shell commands to create the "students" and "courses" collections, and to populate them with sample data:


First, use the use command to switch to the database where you want to create the collections. For example, if you want to use a database named "college", run:


use college



Next, create the "students" collection using the db.createCollection() method:


db.createCollection("students")



To insert data into the "students" collection, use the db.collection.insertMany() method. Here's an example of how to insert the sample data:


db.students.insertMany([
{
"Name": "John Doe",
"Age": 20,
"Gender": "Male",
"Email": "johndoe@example.com",
"Phone Number": "1234567890",
"Address": "123 Main St, Anytown USA"
},
{
"Name": "Jane Smith",
"Age": 19,
"Gender": "Female",
"Email": "janesmith@example.com",
"Phone Number": "0987654321",
"Address": "456 Elm St, Anytown USA"
},
{
"Name": "Bob Johnson",
"Age": 21,
"Gender": "Male",
"Email": "bobjohnson@example.com",
"Phone Number": "5555555555",
"Address": "789 Oak St, Anytown USA"
},
{
"Name": "Sara Lee",
"Age": 18,
"Gender": "Female",
"Email": "saralee@example.com",
"Phone Number": "7777777777",
"Address": "111 Pine St, Anytown USA"
},
{
"Name": "Tom Smith",
"Age": 22,
"Gender": "Male",
"Email": "tomsmith@example.com",
"Phone Number": "2222222222",
"Address": "222 Maple St, Anytown USA"
}
])



Now, create the "courses" collection using the db.createCollection() method:


db.createCollection("courses")



To insert data into the "courses" collection, use the db.collection.insertMany() method. Here's an example of how to insert the sample data:


db.courses.insertMany([
{
"Course Name": "Introduction to Computer Science",
"Instructor Name": "Dr. Jane Doe",
"Course Description": "This course provides an introduction to computer science and programming.",
"Course Duration": "10 weeks"
},
{
"Course Name": "Data Structures and Algorithms",
"Instructor Name": "Dr. John Smith",
"Course Description": "This course covers data structures and algorithms used in computer science.",
"Course Duration": "12 weeks"
},
{
"Course Name": "Database Management Systems",
"Instructor Name": "Dr. Bob Johnson",
"Course Description": "This course covers database management systems.",
"Course Duration": "8 weeks"
},
{
"Course Name": "Web Development",
"Instructor Name": "Dr. Sara Lee",
"Course Description": "This course covers web development technologies such as HTML, CSS, and JavaScript.",
"Course Duration": "10 weeks"
},
{
"Course Name": "Artificial Intelligence",
"Instructor Name": "Dr. Tom Smith",
"Course Description": "This course covers artificial intelligence and machine learning.",
"Course Duration": "12 weeks"
}
])



And that's it! You now have two collections ("students" and "courses") populated with sample data in the "college" database.
Want to print your doc?
This is not the way.
Try clicking the ⋯ next to your doc name or using a keyboard shortcut (
CtrlP
) instead.