The document outlines operations for two MongoDB collections: studentRecords and citizenRecords. It includes instructions for inserting documents, querying for specific criteria, deleting documents based on conditions, and updating fields. Each operation is specified with examples related to student and citizen data management.
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 ratings0% found this document useful (0 votes)
9 views
MongoDB Exercise
The document outlines operations for two MongoDB collections: studentRecords and citizenRecords. It includes instructions for inserting documents, querying for specific criteria, deleting documents based on conditions, and updating fields. Each operation is specified with examples related to student and citizen data management.
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/ 3
1.
Consider a MongoDB collection, studentRecords, with the following fields:
{ "StudentID": 301, "Name": "Karma", "Course": "Data Science and Data Analytics", "GPA": 3.6, "Year": 2, "Phone": "17714567", "Address": "Kanglung, Bhutan", "College": "Sherubtse College" }, { "StudentID": 302, "Course": "Physics", "GPA": 2.8, "Year": 1, "Phone": "77345678", "Address": "Paro, Bhutan", "Age": 23 }, { "StudentID": 303, "Name": "Tashi", "Major": "Mathematics", "GPA": 3.1, "Year": 3, "Email": "[email protected]", "Address": "Wangdue, Bhutan" }, { "StudentID": 304, "Name": "Sonam", "FieldOfStudy": "Computer Science", "GPA": 2.4, "Year": 1, "Phone": "7714567890", "Address": "Thimphu, Bhutan", "College": "GCIT" }, { "StudentID": 305, "Name": "Pem", "Program": "Engineering", "GPA": 2.9, "Year": 4, "Phone": "1775678901", "Residence": "654 Maple St, Phuentsholing, Bhutan" } a) Insert the provided documents into the studentRecords collection. b) Write a query to retrieve the names of all students who have a GPA greater than 3.0. c) Write a query to find all students whose age is greater than 20. d) Write a command to delete all documents where the FieldOfStudy is "Engineering." e) Write a query to update the Phone number for students who have a GPA greater than 3.0, setting it to a new value (e.g., "17000000"). f) Write a query to set the GPA of all students whose GPA is less than 3.0 to 3.0. g) Write a query to retrieve the names and addresses of students who are enrolled in "GCIT.
2. Consider a MongoDB collection, citizenRecords, with the following
documents: { "ID": 501, "FullName": "Karma Wangchuk", "Years": 28, "Gender": "Male", "Job": "Engineer", "Contact": "17712345", "Location": "Thimphu, Bhutan" }, { "ID": 502, "FullName": "Tashi Wangmo", "Years": 22, "Gender": "Female", "Hobby": "Photography", "Email": "[email protected]", "Location": "Paro, Bhutan" }, { "ID": 503, "FullName": "Sonam Dema", "Years": 35, "Gender": "Female", "Job": "Doctor", "Contact": "17776543", "Location": "Wangdue, Bhutan", "Specialization": "Cardiology" }, { "ID": 504, "FullName": "Dorji Tshering", "Years": 40, "Gender": "Male", "Job": "Teacher", "Contact": "77345678", "Location": "Bumthang, Bhutan", "Subjects": ["Math", "Science"], "YearsOfExperience": 15 }, { "ID": 505, "FullName": "Dorji Peldon", "Years": 30, "Gender": "Female", "Job": "Artist", "Contact": "17789012", "Location": "Phuentsholing, Bhutan", "Medium": "Painting", "Exhibitions": 5 } a) Insert the provided documents into the citizenRecords collection. b) Write a query to retrieve the data for the full names " Dorji Peldon " and "Karma Wangchuk." c) Write a query to find all citizens whose job is "Engineer." d) Write a command to delete all documents where the Job is "Student." e) Write a query to update the Contact number for citizens who are older than 25, setting it to a new value (e.g., "17800000"). f) Write a query to increase the age of all citizens by 1 year. g) Write a query to retrieve the full names and locations of citizens who live in "Thimphu.