Professional Documents
Culture Documents
22ad2102a Dbms Lab Work Book Updated On 12-07-2023
22ad2102a Dbms Lab Work Book Updated On 12-07-2023
22AD2102A
STUDENT NAME:
22AD2102A` –Database Management Systems
Table of Contents
1. Installation of POSTGRESQL client & server .............................................................. 3
10. Aggregate Functions, Group by & Having Clauses and Set Operations ............... 98
11. Implement Correlated Nested, Views, Indices and DCL Commands .................. 105
15. Creating the Collection and Drop the collection using MongoDB ....................... 135
16. Insert Document and Query Document in MongoDB collection .......................... 141
Pre-Lab
The Prelab exercise is a homework assignment that links the lecture with the laboratory period -
typically takes 2 hours to complete. The goal is to synthesize the information they learn in lecture
with material from their textbook to produce a working piece of software. Prelab Students attending
a two-hour closed laboratory are expected to make a good-faith effort to complete the Prelab
exercise before coming to the lab. Their work need not be perfect, but their effort must be
real(roughly80percentcorrect).
In-Lab
The In-lab section takes place during the actual laboratory period. The First hour of the laboratory
period can be used to resolve any problems the students might have experienced in completing the
Prelab exercises. The intent is to give constructive feedback so that students leave the lab with
working Prelab software - a significant accomplishment on their part. During the second hour,
students complete the In-lab exercise to reinforce the concepts learned in the Prelab. Students leave
the lab having received feedback on their Prelab and In-lab work.
Post-Lab
The last phase of each laboratory is a homework assignment that is done following the laboratory
period. In the Post-lab, students analyse the efficiency or utility of a given system call. Each Post-lab
exercise should take roughly 120minutes to complete.
LAB CONTINIOUS EVALUATION SHEET
S. No Date Experiment Name Pre-Lab In-Lab Post Lab Viva Total Faculty
(5M) (5M) Voce (50M) Signature
LOGIC EXECUTION RESULT ANALYSIS (5M)
(10M) (10M) (10M) (5M)
14 Create and Drop Database in MongoDB
19 MongoDB indexing
20 Aggregations operations in MongoDB
21 Capstone Project-1
22 Capstone Project-2
23 Capstone Project-3
24 Capstone Project-4
25 Capstone Project-5
26 Capstone Project-6
Experiment # <TO BE FILLED BY STUDENT> Student ID <TO BE FILLED BY STUDENT>
Date <TO BE FILLED BY STUDENT> Student Name <TO BE FILLED BY STUDENT>
Aim/Objective:
To download, install the PostgreSQL which is powerful and open-source object-relational database
system and study the basics of the PostgreSQL.
Description:
PostgreSQL is a popular relational database management system (RDBMS). PostgreSQL is not
controlled by any corporation or other private entity and the source code is available free of charge.
PostgreSQL runs on all major operating systems, including Linux, UNIX and Windows. It supports
text, images, sounds, and video, and includes programming interfaces for C / C++, Java, Perl, Python,
Ruby, Tcl and Open Database Connectivity (ODBC). PostgreSQL supports four standard procedural
languages, which allows the users to write their own code in any of the languages and it can be
executed by PostgreSQL database server. These procedural languages are - PL/pgSQL, PL/Tcl,
PL/Perl and PL/Python. Besides, other non-standard procedural languages like PL/PHP, PL/V8,
PL/Ruby, PL/Java, etc., are also supported.
Pre-Requisites:
The requirement to learn PostgreSQL is knowledge of the database, mainly the RDBMS and
MySQL. It is database software having different settings and procedures.
Pre Lab-Task:
Answer the following question before entering into lab. The following pre lab task has to perform at
home.
In Lab Task
Installation of PostgreSQL
Since version 8.0, PostgreSQL offers an installer for Windows systems that makes the installation process
easier and faster. For development purposes, we will install PostgreSQL version 12 or above version on
Windows 10.
Step 3: - Specify installation folder, choose your own or keep the default folder suggested by
PostgreSQL installer and click the Next button
For the tutorial on this website, you don’t need to install Stack Builder so feel free to uncheck
it and click the Next button to select the data directory:
Step 5: - Select the database directory to store the data or accept the default folder. And click
the Next button to go to the next step:
PostgreSQL runs as a service in the background under a service account named XXXXXXX.
If you already created a service account with the name XXXXXXX, you need to provide the
password of that account in the following window.
After entering the password, you need to retype it to confirm and click the Next button:
Step 7: - Enter a port number on which the PostgreSQL database server will listen. The
default port of PostgreSQL is 5432. You need to make sure that no other applications are
using this port.
Step 8: - Choose the default locale used by the PostgreSQL database. If you leave it as default locale,
PostgreSQL will use the operating system locale. After that click the Next button.
Step 9: - The setup wizard will show the summary information of PostgreSQL. You need to
review it and click the Next button if everything is correct. Otherwise, you need to click the
Back button to change the configuration accordingly.
Now, you’re ready to install PostgreSQL on your computer. Click the Next button to begin
installing PostgreSQL.
Step 10: - Click the Finish button to complete the PostgreSQL installation.
✓ There are several ways to verify the PostgreSQL installation. You can try to connect to the
PostgreSQL database server from any client application e.g., psql and pgAdmin.
✓ The quick way to verify the installation is through the psql program.
First, click the psql application to launch it. The psql command-line program will display.
Second, enter all the necessary information such as the server, database, port, username, and
password. To accept the default, you can press Enter. Note that you should provide the
password that you entered during installing the PostgreSQL.
Third, issue the command SELECT version(); you will see the following output:
Post Lab:
Answer the following question before entering into lab. The following post lab task has to
perform at home.
1) Why we need to model data base.
Aim/Objective:
To download, install the TerraER tool which is designed to help users to learn and practice the basics
of database management.
Description: -
TerraER is a simple to use application which allows you to create data models in a graphic
environment. You can control the number and location of the entities, the relations or intermediate
elements, by manually placing them in the required form. The tool allows you to create diagrams of
entities and relations, in order to study the connections that link them. The elements are customizable,
allowing you to rename, resize and easily relocate them. The building tools include entities and weak
entities, relationships, entity relationships, roles, key / derived / multi-value attributes, connection
cardinality and adjacent functions. You may add disjunctions, overlapping elements, generalizations
and optional / required connections.
Pre-Requisites: The Pre-requisites of TerraER tool is to know the different notations used in it.
Pre Lab-Task:
Answer the following question before entering into lab. The following pre lab task has to perform at
home.
In Lab Task
Installation of TERA ER Tool
TerraER is a free open-source learning tool designed to aid students in the creation of entity-
relationship models. Our main goal is to provide students with a tool that reflects exactly the data
modelling concepts learned in the classroom.
Introduction
Data modelling is one part of the database conceptual design process. The entity-relationship model
(ER model) is a largely used conceptual model proposed by Chen [1]. It defines the entities and the
relationships between these entities. The ER model is simple and easy to understand, making it
intelligible to both database designers and end users
Installation
TerraER is distributed in a single JAR file publicly available for download at our web
site www.terraer.com.br/download_en.html. The JAR file is auto-contained, i.e., it can be placed in
any folder, does not require the installation of additional libraries, and does not change operating
system files (e.g., windows registry). In a nutshell, TerraER requires only a Java Runtime
Environment (JRE) previously installed on the target computer
(www.java.com/en/download/index.jsp).
TerraER was initially designed for academic purposes, i.e., to help students and professors in
the task of creating ER models. Therefore, we developed the graphical user interface to be
practical, intelligible, and intuitive
Course Title Database Management Systems ACADEMIC YEAR: 2023-24
Course Code(s) 22AD2102A Page 18 of 192
Experiment # <TO BE FILLED BY STUDENT> Student ID <TO BE FILLED BY STUDENT>
Date <TO BE FILLED BY STUDENT> Student Name <TO BE FILLED BY STUDENT>
COVID-19 is also known as Corona Virus. It was first reported to the World Health Organization
(WHO) on the31st of December, 2019 in Wuhan, China. Mr. John employed the services of a Data
Analyst for the design of a COVID-19 database. Mr. John gave requirements to the Data Analyst to
carry on his work in designing the database. This database system is helpful in finding out the number
of cases in a particular day and in a particular country. It should also give the no. of persons recovered
or died based on the data stored in the database. By analyzing the data, we can find out the most
Covid affected areas over the globe. This system requires a database for storing the details of all the
countries with their details of country code, name, population count and such other details related to
the country. There should be Person database where all the details of the people are stored who came
for taking the test. Initially the status of the person is taken as negative. There is a need of another
database where the affected person’s data is stored. Data is inserted in to this whenever a person is
found covid positive. It should also contain the information about the recovered or death cases.
Include any other entities which are required according to your requirement.
Viva Questions:
1.Name some of the tools for ER design that are available in the market?
2.List the Advantages & Disadvantages of TerraER Design tool?
3.Justify the importance of TerraER design tool with respect to the real time project
environment?
4.Give the symbol for representing the Relationship in TerraER tool?
5.List out the software industries that are using TerraER tool before the creation of any database
design?
Course Title Database Management Systems ACADEMIC YEAR: 2023-24
Course Code(s) 22AD2102A Page 22 of 192
Experiment # <TO BE FILLED BY STUDENT> Student ID <TO BE FILLED BY STUDENT>
Date <TO BE FILLED BY STUDENT> Student Name <TO BE FILLED BY STUDENT>
Post Lab
Answer the following question before entering into lab. The following post lab task has to
perform at home.
Draw an ER Diagram for the following description.
EMPLOYEE WITH ATTRIBUTES (EMPNO, ENAME, AL, CONTACTNO, DOB, AGE, ADDRESS,
Aim/Objective:
The aim of this program is to draw the Entity Relationship (ER) Diagram for the below case
studies of three and four.
Description:
In this program, we will draw the Entity Relationship (ER) Diagram. ER Diagram stands for
Entity Relationship Diagram, also known as ERD is a diagram that displays the relationship of
entity sets stored in a database. In other words, ER diagrams help to explain the logical structure
of databases. ER diagrams are created based on three basic concepts: entities, attributes and
relationships.
Pre-Requisites:
The machine is to be installed with TerraER software /tools to accomplish the given task.
Pre Lab-Task:
Answer the following question before entering into lab. The following pre lab task has to
perform at home.
1) Explain about derived attributes
In Lab Task
The railway reservation system facilitates the passengers to enquire about the trains available based
on source and destination, booking and cancellation of tickets, enquire about the status of the booked
ticket. Our aim here is to design and develop a database maintaining records of different trains, train
status, and passengers. the record of train includes its number, name, source, destination, and days on
when its available. Passengers can book their tickets for the train in which seats are available. Before
booking a ticket, the validity of train number and booking date is checked. Once they are validated,
seat availability is checked, and ticket is booked. Ticket once booked can be cancelled at any time.
For this we need to provide ticket id. Also consider that initially passenger needs authentication as
well. Design a database for the above scenario. Include the entities whatever are required according to
your requirements.
In a university, there are several departments and each department has a head of department
who belongs to Faculty. Department have a name, phone extension, specific mailing address and
Students that belong to the department. Students can belong to only one Department at a time and
Department can have more than one or no Student. Students and faculty have names and unique
identification numbers, with address, age, gender and other information. Student studies different
Courses offered by university. Faculty teaches these Courses. In each semester one student can take
more than one course and Faculty can teach more than one courses. Faculty members can teach in
multiple Departments. Each course can be taught by many faculty members or no one. Faculty
members are also working on multiple research projects. These projects are funded by government
and university. One project can have more than one faculty member and one faculty member can
work on more than one project.
1. What is an ER Diagram?
2. Why are composite keys important when modelling databases with entity-relationship diagrams?
Post Lab
Answer the following question before entering into lab. The following post lab task has to perform
at home.
Draw an ER Diagram for the case study, University online Exam system.
We are all aware of the current pandemic situation, our university is providing the online exams to
complete the semester on time. These exam systems come with online invigilation and proctoring
features to ensure a fair examination process. This system is very much useful in conducting the
exams online maintain the social distance which is very much to be followed in the current scenario.
Students also will be benefited by not losing their academic year and can continue their studies
without any break.
To design this system, the database should contain the information about courses, sections, exam
details and staff conducting the exam like squad, proctors involved in the exam duty. Courses
database should contain the details of the courses for which exam is being conducted along with the
no. of students enrolled for each exam. Online Exam database contains the exam details like exam
id, exam date, squad etc. Depending on the number of students enrolled for the exam in a course,
rooms should be allotted for the students. This is done in the ROOM database where the no. of
students should not be more than 50 and contains the details of proctors allotted for those rooms.
There is a faculty database which contains the details of the faculty to whom the exam duties should
be allotted. Design a database for the above scenario. Include the entities whatever are required
according to your requirements.
Pre Lab-Task:
Answer the following question before entering into lab. The following pre lab task has to perform at
home.
In Lab Task
Implementation of basic SQL Queries DDL commands, DML commands.
Problem Description:
SAILORS (SID: INTEGER, SNAME: STRING, RATING: INTEGER, AGE: REAL);
BOATS (BID: INTEGER, BNAME: STRING, COLOR: STRING);
RESERVES (SID: INTEGER, BID: INTEGER, DAY: DATE).
Questions:
1. Create tables for Sailors, Reserves and Boats with appropriate key constraints?
2. Write SQL Queries to insert values as per the given above Data Base?
3. To retrieve distinct Sailor name and Sailor Age from Sailors?
4. To retrieve boat name, boat id of the red and green color boats?
5. Find the names of sailors who have reserved a red boat, and list in the order of age?
6. Find the ids of sailors who have reserved a red boat or a green boat?
7. Find the names of sailors who have reserved at least one boat?
8. Display the Insert ‘twenty’ in age column
9. Display the Insert sid: 100 bid: 205, day: 12-09-17 in reserves table.
10. Create a query that displays the Insert sid: 95, Sname: anil, Rating:3, age: 64 in sailor’s
table.
11. Create a query that displays the update 10.5 as rating where sailor id= 95
12. In the reserves table give date as per this format like did/mm/yyy
1. What is the difference between Drop, Delete and Truncate statements in postgreSQL?
2. list various DDL commands
3. List various DML commands
4. Differentiate the commands ALTER and UPDATE
5. What is the use of Select command in postgreSQL?
Post Lab:
Answer the following question before entering into lab. The following post lab task has to perform at
home.
Use the tables below and implement the below queries
CUSTOMER ARTIST
PAINTING
CID CNAME ADDRESS PHONE CATEGORY
100 RAJU HYDERABAD 9876045789 BRONZE
101 HARI VIJAYAWADA 8877678956 GOLD
102 DEVI GUNTUR 7879312123 SILVER
103 RANI DELHI 8780945290 PLATINUM
104 JAYA MUMBAI 9612578457 GOLD
105 HARITHA KOLKATA 9611665513 SILVER
106 KALYAN VIJAYAWADA 9610752569 BRONZE
107 ROJA HYDERABAD 9609839625 PLATINUM
108 AMAR VIJAYAWADA 9608926681 GOLD
109 PADMA VIJAYAWADA 9608013737 BRONZE
OWNER
PID OID NAME ADDRESS PHONE
300 500 RAJU HYDERABA 9460367777 RENT
D
301 500 HARI VIJAYAWAD 8134185751 PID AID RENTAL_ TYPE
A COST
302 501 GIRI HYDERABA 7808003725 300 201 4500 HIRED
D 301 202 3500 NOT HIRED
303 501 GOPI DELHI 9481821699
302 203 7500 HIRED
304 503 KRISH MUMBAI 7155639673
303 205 2500 NOT HIRED
NA
305 502 VERM DELHI 8829457647 304 202 10000 NOT HIRED
A 305 201 8000 NOT HIRED
306 502 GUNA DELHI 7503275621
306 203 6500 NOT HIRED
Questions
1. Create the tables identifying the constraints and relationships
2. Insertatleast10recordsinto these tables
3. Display the customer details who got the category as “Gold”
4. Display the list of artists who belong to “Hyderabad”
5. Create a query display the painting details which are not hired
6. Create a query to update the rental cost of the painting with 1000forthepaintings which are not
hired
7. Display the details of the artist whose paintings are hired
In Lab Task
Implementation of distinct types of Joins: Inner Join, Outer Join, Natural Join etc.
ENTITIES ATTRIBUTES
CUSTOMER CUST_ID, CUST_NAME, DOB, CITY, STREET, STATE, PINCODE,
PH_NO, DEAL_NO, PHOTO_IDENTITY,
V_ID
VEHICLE V_ID, VEH_TYPE, VEH_NAME, VEH_NUMBER
EDU_BUS EDU_ID, EDU_NAME, PH_NO,
CITY,STREET,STATE,PINCODE,DEAL_NO
DEALER DEAL_ID, DEAL_NAME, CITY, STREET,
STATE,PINCODE,D_NO,PH_INT
BRANCH BRANCH_ID, B_NAME, STATE, CITY, PINCODE, STREET, D_NO,
PHNO1, PHNO2,
C_ID, V_ID, E_ID
RENEWAL BRACH_ID, CID, CHECK_LICENSE_PERIOD
REGISTRATION CUST_ID, V_ID, DEALID, DATE
CONTRACT_PERMISSION V_ID, BRANCH_ID, NO_OF_DAYS, AMOUNT_PER_SEAT
CUSTOMER
VEHICLE
EDU_BUS
DEALER
BRANCH
RENEWAL REGISTRATION
CONTRACT_PERMISSION
Questions:
1. Create the database in PostgreSQL and create the necessary tables for the given case study using
appropriate keys and relationships between the tables
2. Display the vehicles that were registered by the dealer name 'Raghu'
3. Display the list of customers who have applied for new license
4. Display the vehicles who have been given 30 days of contract permission.
5. Create a query to display all the records who applied for renewal of license.
6. Display the count of vehicles of different types.
7. Create a query to display customer details who have 2-wheeler vehicle.
8. Create a query that displays the customer details whose license expires in 5 days.
9. Display the list of educational institutions who applied for permit.
10.Display the total number of vehicles license allotted by each branch.
11.Display the number of customer present under each dealer.
Post Lab
Answer the following question before entering into lab. The following post lab task has to perform at home.
Use the tables below and implement the below queries
Student:
REGNO NAME ADDRESS PHONE AGE
101 SAI VIJAYAWADA 9455123451 18
102 TEJA GUNTUR 9652431543 18
103 DINESH DELHI 9156253131 20
104 TAURN CHENNAI 9156768971 18
105 DHANRAJ MUMBAI 9156253132 19
106 ROHIT BANGALORE 9652431544 18
107 NIRAJ GOA 9455123452 18
Course:
COURSE_ID REG NO
1 101
2 102
2 103
3 104
4 105
5 106
1 107
Project:
PROJECTID EMPID CLIENTID PROJECTNAME PROJECTSTARTDATE
1. All the rows of the table on the left side of the join and matches rows for the table on the right side
of the join
2. Creates the result-set by combining results of both LEFT JOIN and RIGHT JOIN
Pre-Requisites:
The machine is to be installed with PostgreSQL software /tools to accomplish the given task
Pre Lab-Task
Answer the following question before entering into lab. The following pre lab task has to perform at home
1. What it means ‘%S__k’
In Lab Task:
Use the tables and data in Experiment–5, In-Lab section and work on the following queries
Post Lab: -
Answer the following question before entering into lab. The following post lab task has to perform at home.
WORKER:
1 MANAGER 2016-02-2000:00:00
2 EXECUTIVE 2016-06-1100:00:00
8 EXECUTIVE 2016-06-1100:00:00
5 MANAGER 2016-06-1100:00:00
4 ASST.MANAGER 2016-06-1100:00:00
7 EXECUTIVE 2016-06-1100:00:00
6 LEAD 2016-06-1100:00:00
3 LEAD 2016-06-1100:00:00
1. Create the database in PostgreSQL and create the necessary tables for the given case study using
appropriate keys and relationships between the tables
2. Create a SQL query to display employees details whose salary is greater than 30000 and less than
50000
3. Display the no. of employees in each department
4. Display the count of employees with same designation in an organization
Description:
In this program, we will implement to implement sub queries and views in postgreSQL. Subqueries are queries that
are nested within another SQL query. A subquery can contain more than one query inside it, one after another.
They allow us to select specific rows that satisfy certain conditions at the run time. They are also known as the inner
query or inner select, and the query that contains them is known as the outer query or outer select. Subqueries are
nested inside statements like SELECT, INSERT, UPDATE, DELETE, or any other subquery. A View in SQL is simply a
virtual table created based on a result set of another SQL statement. Views were introduced to reduce the
complexity of multiple tables and deliver data in a simple manner. Views help us maintain data integrity and
provide security to the data, thus acting as a security mechanism.
Pre-Requisites:
The machine is to be installed with PostgreSQL software /tools to accomplish the given task
Pre Lab-Task
Answer the following question before entering into lab. The following pre lab task has to perform at home
1. Explain about various conditional operators in SQL
In Lab Task
PATIENT:
PID FNAME LNAME EMAIL PHNO ADDRESS DATE_ADMN
PCASE SHIFT
BEDNUM PID DOCTOR ID DAY STARTTI ENDTIME
ME
20 200
100 12-04-2020 9 5
21 201
101 20-06-2020 4 8
22 202
102 01-08-2020 6 12
23 203
105 05-08-2020 13 18
24 204 13-10-2019
106 4 8
25 205 22-01-2020 6 12
107
26 206 108 15-03-2020 13 18
27 207 06-07-2020
109 9 5
28 208 110 12-03-2020 4 8
29 209 05-02-2020 6 12
111
112 22-04-2020 13 18
PID AMT
113 10-07-2020 4 8
200 200 03-03-2020 6 12
114
201 200
115 22-04-2020 13 18
202 300
203 600
204 200
205 300
206 200
APPOINTMENT
207 200
208 200
209 600
Question:
1. Write an POSTGRESQL query to display who are patients required to stay in the hospital?
2. Write an POSTGRESQL query to display who paid amount between 1000 and 3000 for the appointment
3. Write an POSTGRESQL query to calculate average amount of appointment.
4. Write an POSTGRESQL query to display patient number in descending order
5. Write an POSTGRESQL query to display bed number of patient with least patient id.
6. Write query for creating view from patient table.
7. Write a POSTGRESQL query to update view the Patient view where patientid >3 by using replace
view statement
8. Display the patient date of joining into format “dd month yyyy’ for example as “24 March 2020”
9. Display the patient joining time in 24-hour format. For eg: 3:30pm should be displayed as 15:30
10. Write a POSTGRESQL query to display count of patients who come from same city.
11. Write a POSTGRESQL query to first name of patient who admitted and allotted the bed no.
Post Lab
Answer the following question before entering into lab. The following post lab task has to
perform at home.
1. Write a Query to display Patient name who has paid the Highest room rent?
2. Write a Query to display the Doctor id who treated the patient admitted in bedno 24
2. What is PL/SQL?
In Lab Task
Execute the following queries:
1. Write a PL/SQL stored procedure to know the current age of customers who are associated with
APtransport department.
2. Write a PL/SQL stored function to know that, from how many years vehicles are registered with the
APtransport department.
3. Create a trigger before insert to maintain the summary of Dealer Center table into Dealer Center
stats. Whenever the capacity of Dealer Centers is increased or decreased then the total statistics
should be reflectedin Dealer Center stats
4. Create trigger after insert in members table, a trigger should check the value of attribute name and
if it is updated then show the message for updating on name in reminder table.
Post Lab
Answer the following question before entering into lab. The following post lab task has to perform at home.
Problem Description:
1. Write a PL/SQL function that returns the level of customer based on credit limit in customer’s table
2. Write a PL/SQL procedure without parameter to get the count of records in the account table.
3. Write a PL/SQL procedure that returns the number of orders by order status from orders table?
TEST CASES:
4. What are the steps that need to be performed to use an explicit cursor? Discuss briefly.
In Lab Task
Use the tables and data in Experiment– 5
1. Write a PL/SQL stored procedure to know the current age of customers who are
associated with AP transport department.
2. Write a PL/SQL stored function to know that, from how many years vehicles are
registered with the A.P transport department.
3. Create a trigger before insert to maintain the summary of Dealer Center table into Dealer
Center stats. Whenever the capacity of Dealer Centers is increased or decreased then the total
statistics should be reflected in Dealer Center stats
4. Create trigger after insert in members table, a trigger should check the value of attribute
name and if it is updated then show themes age for updating on name in reminder table.
Post Lab
Answer the following question before entering into lab. The following post lab task has to perform at home.
Use the tables and data in Experiment– 6
1. Write PL/SQL program to display doctor appointment fee amount value.
3. Write a PL/SQL program using functions to display the address details from where the number of
4. What are the steps that need to be performed to use an explicit cursor? Discuss briefly.
In Lab Task
Employee Database an Enterprise wishes to maintain a database to automate its operations. Enterprise
is divided into certain departments and each department consists of employees. The following two
tables describes the automation schemas DEPT (DEPTNO, DNAME, LOC) EMP (EMPNO, ENAME,
JOB, MGR, HIREDATE, SAL, COMM, DEPTNO)
1. Update the employee salary by 15%, whose experience is greater than 10 years.
2. Delete the employees, who completed 30 years of service.
3. Display the manager who is having maximum number of employees working under him?
4. Create a view, which contain employee names and their manager
Answer the following question before entering into lab. The following post lab task has to perform at
home.
1. Create Sales table with the following fields (SALES NO, SALESNAME, BRANCH, SALES
AMOUNT, DOB)
2. Insert at least 10 record sin to every table that is implemented in the case study
3. Calculate total Sales Amount in each branch
4. Calculate average Sales Amount in each branch.
5. Display all the salesmen, DOB who are born in the month of December as day in
character format i.e., 21-Dec-09
6. Display the name and DOB of salesman in alphabetical order of the month.
Description:
Correlated nested queries, also known as correlated subqueries, are SQL queries in which the inner query
references values from the outer query. The inner query is executed for each row of the outer query, allowing for
dynamic and contextual data retrieval. correlated nested queries, views, indices, and DCL commands are important
components of a DBMS. They contribute to data retrieval, abstraction, performance optimization, security, data
integrity, and efficient database administration.
Pre-Requisites:
This Section contains the list of Software/Tools or required knowledge (Glossary) to complete the task under the
Laboratory Session.
Pre Lab-Task
Answer the following question before entering into lab. The following pre lab task has to perform at home
In Lab Task
Use the tables and data in Experiment – 5, In-Lab section and work on the following queries
Answer the following question before entering into lab. The following post lab task has to perform at home.
CONSIDER THE FOLLOWING SCHEMA: SAILORS (SID, SNAME, RATING, AGE) BOATS (BID, BNAME,
COLOR) RESERVES (SID, BID, DAY(DATE))
1. Find the names of the sailors who have reserved both a red or a yellow boat
2. Find all SIDs of sailors who have a rating of 10 or have reserved boat 111.
3. Find the names of sailors who have reserved a red boat, and list in the order of age
4. Find the names of sailors who have reserved boat 103.
5. Find the name and the age of the youngest sailor.
6. Find the ids and names of sailors who have reserved two different boats on the same day
Aim/Objective:
The aim of implementing transactions in SQL Server is to ensure the atomicity, consistency, isolation,
and durability (ACID) properties of database operations.
Description:
Transactions in SQL Server provide a mechanism to group multiple database operations into a single
logical unit, ensuring that they are executed as a whole or not at all. Transactions ensure the atomicity,
consistency, isolation, and durability (ACID) properties of database operations. In SQL Server,
transactions are managed using the BEGIN TRANSACTION, COMMIT, and ROLLBACK statements.
Pre-Requisites:
This Section contains the list of Software/Tools or required knowledge (Glossary) to complete the task
under the Laboratory Session.
Pre Lab-Task
Answer the following question before entering into lab. The following pre lab task has to perform at
home.
1. What are Transactions?
In Lab Task
Implementation of Transaction in SQL Server
Student Data:
REGNO NAME ADDRESS PHONE AGE
101 SAI VIJAYAWADA 9455123451 18
102 TEJA GUNTUR 9652431543 18
103 DINESH DELHI 9156253131 20
104 TAURN CHENNAI 9156768971 18
103 DINESH DELHI 9156253131 20
102 TEJA GUNTUR 9652431543 18
✓ Delete those records from the table which have age = 20 and then ROLLBACK the changes in the
database.
✓ Write the SQL queries delete those records from the table which have age = 20 and then COMMIT
the changes in the database.
✓ Delete those records from the table which have age = 18 and then COMMIT the changes and then
try to use ROLLBACK to the previous save point. What you observed at this stage?
Answer the following question before entering into lab. The following post lab task has to perform at home.
1. Consider a simple checkpointing protocol and the following set of operations in the log. (start, T4);
(write, T4, y, 2, 3); (start, T1); (commit, T4); (write, T1, z, 5, 7); (checkpoint); (start, T2); (write,
T2, x, 1, 9); (commit, T2); (start, T3), (write, T3, z, 7, 2); If a crash happens now the system tries to
recover using both undo and redo operations, what are the contents of the undo list and the redo list.
(A) Undo: T3, T1; Redo: T2 (B) Undo: T3, T1; Redo: T2, T4 (C) Undo: none; Redo; T2, T4, T3, T1
(D) Undo: T3, T1, T4; Redo: T2
2. Consider the following transaction involving two bank accounts x and y. read(x); x: = x–50;
write(x); read(y); y: =y+50; write(y) The constraint that the sum of the accounts x and y should
remain constant is that of (A) Atomicity (B) Consistency (C) Isolation (D) Durability
Aim/Objective:
The aim of this experiment is to install the Mongodb software in windows/Linux/Macos operating
system
Description:
MongoDB is the most popular NoSQL database, is an open-source document-oriented database. The
term ‘NoSQL’ means ‘non-relational’. It means that MongoDB isn’t based on the table-like relational
database structure but provides an altogether different mechanism for storage and retrieval of data. This
format of storage is called BSON. MongoDB was designed to work with commodity servers. Now it is
used by the company of all sizes, across all industry.
In this experiment, we will provide the sequence of steps for installing of the Mongodb software in
windows/Linux/Macos.
Pre-Requisites:
This Section contains the list of steps or required knowledge (Glossary) to complete the task under the
Laboratory Session. Before Learning MongoDB, the students must have the basic knowledge of
SQL& OOP's.
Pre Lab-Task
Answer the following question before entering into lab. The following pre lab task has to perform at
home.
2. What does ACID stand for in the context of databases, and is MongoDB ACID-compliant?
Materials:
Procedure:
1. Download the MongoDB installation package from the official MongoDB website
(https://www.mongodb.com/try/download/community).
2. Locate the downloaded installation package and run the installer.
3. Choose the setup type (Complete or Custom) based on your preference.
4. Accept the license agreement and click "Next."
5. Choose the destination folder where MongoDB will be installed or leave it as the default location.
Click "Next."
6. Select the components you want to install (MongoDB Server, MongoDB Compass, etc.). Click
"Next."
7. Configure the MongoDB service by choosing either "Run service as Network Service user" or "Run
service as a local or domain user." Click "Next."
8. Configure the MongoDB data directory by specifying the path where the database files will be
stored. Click "Next."
9. Choose whether to install MongoDB as a Windows service or not. Click "Next."
10. Review the installation summary and click "Install" to start the installation process.
11. Wait for the installation to complete. Once finished, click "Finish."
12. Open the command prompt or PowerShell as an administrator.
13. Navigate to the MongoDB installation directory (e.g., C:\Program
Files\MongoDB\Server\{version}\bin).
14. Run the mongod command to start the MongoDB server.
15. Open another command prompt or PowerShell as an administrator.
16. Navigate to the MongoDB installation directory.
17. Run the mongo command to start the MongoDB shell.
18. Verify the installation by executing MongoDB commands in the shell (e.g., db.version() to check
the MongoDB version).
Observations:
Materials:
Procedure:
1. Locate the MongoDB configuration file named mongod.cfg. By default, it is located in the
C:\Program Files\MongoDB\Server\{version}\bin directory.
2. Open the mongod.cfg file using a text editor.
3. Modify the configuration options based on your requirements. For example:
o Change the port option to specify a different port number (default: 27017).
o Modify the bindIp option to listen on a specific IP address or bind to all available IP
addresses.
o Configure the storage options to specify a different data directory or enable journaling.
o Customize other options such as logpath, logappend, etc., as needed.
4. Save the changes to the mongod.cfg file.
5. Restart the MongoDB server by stopping the existing instance and starting it again.
6. Open the command prompt or PowerShell as an administrator.
7. Navigate to the MongoDB installation directory.
8. Run the mongod command to start the MongoDB server.
9. Open another command prompt or PowerShell as an administrator.
10. Navigate to the MongoDB installation directory.
11. Run the mongo command to start the MongoDB shell.
12. Verify the configuration changes by executing MongoDB commands and checking the updated
settings (e.g., db.serverCmdLineOpts() to view the server command line options).
Aim/Objective:
The aim of this experiment is to creation of database and dropping of that created database.
Description:
In this experiment, we will create a database in mongodb by using the commands in the mongodb shell.
Pre-Requisites:
This Section contains the list of Software/Tools or required knowledge (Glossary) to complete the task
under the Laboratory Session.
Pre Lab-Task
Answer the following question before entering into lab. The following pre lab task has to perform at home.
Objective: To create and drop a database in MongoDB using the MongoDB shell.
Materials:
MongoDB installed and running (follow the installation steps mentioned earlier)
Procedure:
To Drop a Database:
1. To drop a database, ensure that you are connected to the correct database in the MongoDB shell.
2. Execute the db.dropDatabase() command to drop the currently selected database.
3. The shell will display a confirmation message indicating the database has been dropped.
Observations:
• The database creation command (use) switches to the specified database successfully.
• The current database name is displayed correctly.
• Collections and documents can be created and manipulated within the database.
• The db.dropDatabase() command successfully deletes the database.
Objective: To create and drop a database in MongoDB using a MongoDB driver (e.g., Python).
Materials:
• MongoDB installed and running (follow the installation steps mentioned earlier)
• MongoDB driver for your programming language (e.g., pymongo for Python)
Procedure:
1. Install the MongoDB driver for your chosen programming language (e.g., pymongo for Python).
2. Open a text editor or IDE and create a new script file.
3. Import the required MongoDB driver module in your script.
4. Establish a connection to the MongoDB server using the driver's connection methods.
5. To create a database, use the driver's appropriate method (e.g., client.list_database_names()
in pymongo).
6. Verify the successful creation of the database by checking if it appears in the list of available
databases.
7. Perform database operations such as creating collections, inserting documents, etc., using the
driver's methods.
To Drop a Database:
1. To drop a database, ensure that you are connected to the MongoDB server using the driver.
2. Use the appropriate method provided by the driver to drop the database (e.g.,
client.drop_database() in pymongo).
3. Verify the database deletion by checking if it is no longer listed in the available databases.
Observations:
Aim/Objective:
The aim of this experiment is to creation of collection and dropping of collection in Mongodb.
Description:
Creating a collection in MongoDB involves defining a logical container to store related documents. A collection is
analogous to a table in a relational database and provides a structure for organizing and storing data. When
creating a collection, we specify a name for the collection and may also define indexes or additional configuration
options. Deleting a collection in MongoDB refers to the removal of an entire collection and all its associated
documents. This operation permanently deletes the collection and its data, so it should be performed with caution.
Deleting a collection is irreversible, and the data cannot be recovered once the deletion is complete.
Pre-Requisites:
This Section contains the list of Software/Tools or required knowledge (Glossary) to complete the task
under the Laboratory Session.
Pre Lab-Task
Answer the following question before entering into lab. The following pre lab task has to perform at home.
4. What is the difference between the $and and $or operators in MongoDB queries?
Objective: To create and drop a collection in MongoDB using the MongoDB shell.
Materials:
• MongoDB installed and running (follow the installation steps mentioned earlier)
Procedure:
1. Open the command prompt or PowerShell as an administrator.
2. Navigate to the MongoDB installation directory.
3. Run the mongo command to start the MongoDB shell.
4. By default, the shell connects to the test database. To switch to a different database or create a new
one, use the use command. For example, to switch to a database named mydatabase, enter the
following command:
use mydatabase
5. The shell will output switched to db mydatabase to confirm the database switch.
6. To create a collection, use the db.createCollection() command. Specify the collection name as
an argument. For example, to create a collection named mycollection, enter the following
command:
db.createCollection("mycollection")
The shell will output { "ok" : 1 } to indicate that the collection has been created
6. To verify the creation of the collection, use the db.getCollectionNames() command to retrieve a
list of collections in the current database.
7. Perform collection operations such as inserting documents, querying, updating, etc., in the current
database and collection.
To Drop a Collection:
1. To drop a collection, ensure that you are connected to the correct database in the MongoDB shell.
2. Execute the db.collectionName.drop() command, where collectionName is the name of the
collection you want to drop. For example, to drop the mycollection collection, enter the following
command:
db.mycollection.drop()
The shell will output { "ok" : 1 } to indicate that the collection has been dropped.
Observations:
• The collection creation command (db.createCollection()) creates the collection successfully.
• The db.getCollectionNames() command lists the created collection.
• Operations such as inserting documents, querying, updating, etc., can be performed in the
collection.
• The collection drop command (db.collectionName.drop()) successfully deletes the collection.
Objective: To create and drop a collection in MongoDB using a MongoDB driver (e.g., pymongo for
Python).
Materials:
• MongoDB installed and running (follow the installation steps mentioned earlier)
• MongoDB driver for your programming language (e.g., pymongo for Python)
Procedure:
1. Install the MongoDB driver for your chosen programming language (e.g., pymongo for Python).
2. Open a text editor or IDE and create a new script file.
3. Import the required MongoDB driver module in your script.
4. Establish a connection to the MongoDB server using the driver's connection methods.
5. To create a collection, use the appropriate method provided by the driver (e.g.,
db.create_collection() in pymongo).
6. Verify the successful creation of the collection by checking if it appears in the list of collections in
the current database.
7. Perform collection operations such as inserting documents, querying, updating, etc., using the
driver's methods.
To Drop a Collection:
1. To drop a collection, ensure that you are connected to the MongoDB server using the driver.
2. Use the appropriate method provided by the driver to drop the collection (e.g.,
db.collection_name.drop() in pymongo).
3. Verify the collection deletion by checking if it is no longer listed in the collections of the current
database.
Aim/Objective:
The aim of this experiment is to Inserting a document in a collection and querying the document in
Mongodb.
Description:
Inserting a document in a MongoDB collection involves adding a new record or document that conforms to
the collection's schema or structure. A document in MongoDB is represented in JSON-like format,
consisting of key-value pairs. Querying documents in a MongoDB collection involves retrieving specific
data that matches certain criteria from the collection. MongoDB provides a flexible and powerful querying
mechanism that allows us to find documents based on various conditions, such as matching field values,
using comparison operators, logical operators, or regular expressions.
Pre-Requisites:
This Section contains the list of Software/Tools or required knowledge (Glossary) to complete the task
under the Laboratory Session.
Pre Lab-Task
Answer the following question before entering into lab. The following pre lab task has to perform at home.
Objective: To insert documents into a MongoDB collection and perform query operations using the
MongoDB shell.
Materials:
• MongoDB installed and running (follow the installation steps mentioned earlier)
Procedure:
use mydatabase
5. The shell will output switched to db mydatabase to confirm the database switch.
6. To insert documents into a collection, use the db.collectionName.insertOne() or
db.collectionName.insertMany() command, depending on whether you want to insert a single
document or multiple documents. Replace collectionName with the actual name of the collection.
For example, to insert a document into a collection named mycollection, enter the following
command:
Perform query operations such as filtering, sorting, and projection using the appropriate query
operators in the find() command.
Observations:
Experiment: Insert and Query Documents in MongoDB Collection using a MongoDB Driver
Objective: To insert documents into a MongoDB collection and perform query operations using a
MongoDB driver (e.g., pymongo for Python).
Materials:
• MongoDB installed and running (follow the installation steps mentioned earlier)
• MongoDB driver for your programming language (e.g., pymongo for Python)
Procedure:
1. Install the MongoDB driver for your chosen programming language (e.g., pymongo for Python).
2. Open a text editor or IDE and create a new script file.
3. Import the required MongoDB driver module in your script.
4. Establish a connection to the MongoDB server using the driver's connection methods.
5. Switch to the desired database using the driver's methods (e.g., client.get_database() in
pymongo).
6. To insert documents into a collection, use the appropriate method provided by the driver (e.g.,
db.collection_name.insert_one() or db.collection_name.insert_many() in pymongo).
7. Verify the successful insertion of documents.
8. Perform query operations using the driver's methods to retrieve documents from the collection.
9. Use query operators and filters to refine the query results.
Observations:
Aim/Objective:
The aim of this experiment is to perform the tasks of updating and deleting the documents in MongoDB.
Description:
Updating documents in a MongoDB collection involves modifying existing data within a document or
multiple documents. MongoDB provides powerful update operators that allow us to modify specific fields
or entire documents based on specified criteria. Deleting documents in a MongoDB collection involves
removing one or more documents based on specific criteria. MongoDB offers the deleteOne() and
deleteMany() methods for deleting documents.
Pre-Requisites:
This Section contains the list of Software/Tools or required knowledge (Glossary) to complete the task
under the Laboratory Session.
Pre Lab-Task
Answer the following question before entering into lab. The following pre lab task has to perform at home.
5. What is the difference between a single-field index and a compound index in MongoDB?
Objective: To update and delete documents in a MongoDB collection using the MongoDB shell.
Materials:
• MongoDB installed and running (follow the installation steps mentioned earlier)
Procedure:
use mydatabase
5. The shell will output switched to db mydatabase to confirm the database switch.
6. To update documents in a collection, use the db.collectionName.updateOne() or
db.collectionName.updateMany() command, depending on whether you want to update a single
document or multiple documents. Replace collectionName with the actual name of the collection.
For example, to update a document in a collection named mycollection where the "name" field is
"John", enter the following command:
db.mycollection.updateOne({ "name": "John" }, { $set: { "age": 31 } })
This command updates the "age" field of the document matching the query.
7. To verify the successful update of documents, use the db.collectionName.find() command to
retrieve the updated documents in the collection.
8. To delete documents from a collection, use the db.collectionName.deleteOne() or
db.collectionName.deleteMany() command, depending on whether you want to delete a single
document or multiple documents. Replace collectionName with the actual name of the collection.
For example, to delete a document in a collection named mycollection where the "name" field is
"John", enter the following command:
db.mycollection.deleteOne({ "name": "John" })
Observations:
• The database and collection are created successfully.
• Documents can be updated in the collection using the updateOne() or updateMany()
• The find() command retrieves the updated documents from the collection.
• Documents can be deleted from the collection using the deleteOne() or deleteMany() command.
• The find() command after deletion displays the remaining documents in the collection.
Objective: To update and delete documents in a MongoDB collection using a MongoDB driver (e.g.,
pymongo for Python).
Materials:
• MongoDB installed and running (follow the installation steps mentioned earlier)
• MongoDB driver for your programming language (e.g., pymongo for Python)
Procedure:
1. Install the MongoDB driver for your chosen programming language (e.g., pymongo for Python).
2. Open a text editor or IDE and create a new script file.
3. Import the required MongoDB driver module in your script.
4. Establish a connection to the MongoDB server using the driver's connection methods.
5. Switch to the desired database using the driver's methods (e.g., client.get_database() in
pymongo).
6. To update documents in a collection, use the appropriate method provided by the driver (e.g.,
db.collection_name.update_one() or db.collection_name.update_many() in pymongo).
7. Verify the successful update of documents.
8. To delete documents from a collection, use the appropriate method provided by the driver (e.g.,
db.collection_name.delete_one() or db.collection_name.delete_many() in pymongo).
9. Verify the successful deletion of documents.
Observations:
18.MongoDB Projection
Aim/Objective:
The aim of this experiment is to control and shape the data returned in query results by specifying which
fields to include or exclude from the result set.
Description:
MongoDB projection is a feature that allows developers to control the fields returned in query results,
shaping the structure and content of the retrieved documents. It provides a mechanism to include or exclude
specific fields from the result set, helping optimize performance and reduce unnecessary data transfer.
MongoDB projection plays a crucial role in optimizing query performance, reducing network overhead,
and tailoring the structure of query results to meet specific application requirements. By carefully defining
the projected fields, developers can streamline data retrieval and improve overall application efficiency.
Pre-Requisites:
This Section contains the list of Software/Tools or required knowledge to complete the task under the
Laboratory Session.
Pre Lab-Task
Answer the following question before entering into lab. The following pre lab task has to perform at home.
4. What is the difference between a shard key and a shard tag in MongoDB?
In-lab:
MongoDB Projection
Objective: To perform projection operations in MongoDB, selecting specific fields to include or exclude
from query results.
Materials:
• MongoDB installed and running (follow the installation steps mentioned earlier)
Procedure:
use mydatabase
5. The shell will output switched to db mydatabase to confirm the database switch.
6. To query documents from a collection with projection, use the db.collectionName.find()
command with the projection parameter. Replace collectionName with the actual name of the
collection. For example, to query documents from a collection named mycollection and include
only the "name" and "age" fields in the result, enter the following command:
db.mycollection.find({}, { "name": 1, "age": 1 })
The { "name": 1, "age": 1 } object specifies the fields to include in the result. Fields set to 1
are included, while fields set to 0 are excluded.
Perform various projection operations by specifying different fields and their inclusion or exclusion.
Observations:
Objective: To perform projection operations in MongoDB using a MongoDB driver (e.g., pymongo for
Python).
Materials:
• MongoDB installed and running (follow the installation steps mentioned earlier)
• MongoDB driver for your programming language (e.g., pymongo for Python)
Procedure:
1. Install the MongoDB driver for your chosen programming language (e.g., pymongo for Python).
2. Open a text editor or IDE and create a new script file.
3. Import the required MongoDB driver module in your script.
4. Establish a connection to the MongoDB server using the driver's connection methods.
5. Switch to the desired database using the driver's methods (e.g., client.get_database() in
pymongo).
6. To query documents from a collection with projection, use the appropriate method provided by the
driver (e.g., db.collection_name.find({}, projection) in pymongo).
7. Specify the projection parameter as a dictionary or object containing the fields to include or exclude
from the result. For example, to include only the "name" and "age" fields, use the following code:
Iterate through the cursor object to retrieve and process the query results.
Perform various projection operations by specifying different fields and their inclusion or exclusion.
Observations:
19.MongoDB indexing
Aim/Objective:
The aim of this experiment is to improve query performance and data retrieval efficiency by creating data
structures that allow for faster search and retrieval of information. Indexing enables MongoDB to locate
and retrieve specific documents more efficiently, reducing the need to scan the entire collection.
Description:
Indexing in MongoDB is a mechanism that enhances query performance and data retrieval efficiency. It
involves creating data structures, called indexes, that provide a way to access and retrieve specific
information from a MongoDB collection quickly.
When indexing is applied to a field or a combination of fields, MongoDB creates a separate data structure
that organizes the indexed field(s) in a sorted manner. This structure, known as the index, contains
references to the actual documents in the collection.
Pre-Requisites:
This Section contains the list of Software/Tools or required knowledge (Glossary) to complete the task
under the Laboratory Session.
Pre Lab-Task
Answer the following question before entering into lab. The following pre lab task has to perform at home.
3. What is the difference between a TTL index and a regular index in MongoDB?
In-lab:
MongoDB Indexing
Objective: To create and use indexes in MongoDB for improved query performance.
Materials:
• MongoDB installed and running (follow the installation steps mentioned earlier)
Procedure:
use mydatabase
5. The shell will output switched to db mydatabase to confirm the database switch.
6. Identify the collection on which you want to create an index. For example, consider a collection
named mycollection.
7. To create an index on a specific field, use the db.collectionName.createIndex() command.
Replace collectionName with the actual name of the collection and fieldName with the name of the
field to index. For example, to create an index on the "name" field, enter the following command:
db.mycollection.createIndex({ "name": 1 })
This command creates a ascending index on the "name" field. You can specify -1 for a descending
index.
Once the index is created, perform query operations on the collection and observe the improved query
performance.
Optionally, you can use the db.collectionName.getIndexes() command to view the list of indexes
created on a collection.
Observations:
Objective: To create and use indexes in MongoDB for improved query performance using a MongoDB
driver (e.g., pymongo for Python).
Materials:
• MongoDB installed and running (follow the installation steps mentioned earlier)
• MongoDB driver for your programming language (e.g., pymongo for Python)
Procedure:
1. Install the MongoDB driver for your chosen programming language (e.g., pymongo for Python).
2. Open a text editor or IDE and create a new script file.
3. Import the required MongoDB driver module in your script.
4. Establish a connection to the MongoDB server using the driver's connection methods.
5. Switch to the desired database using the driver's methods (e.g., client.get_database() in
pymongo).
6. Identify the collection on which you want to create an index. For example, consider a collection
named mycollection.
7. To create an index on a specific field, use the appropriate method provided by the driver (e.g.,
db.collection_name.create_index() in pymongo). For example, to create an index on the
"name" field, use the following code:
db.collection_name.create_index([("name", pymongo.ASCENDING)])
This code creates an ascending index on the "name" field. You can use pymongo.DESCENDING for a
descending index.
8. Once the index is created, perform query operations on the collection and observe the improved
query performance.
9. Optionally, you can use the appropriate method provided by the driver (e.g.,
db.collection_name.index_information() in pymongo) to view the list of indexes created on a
collection.
Aim/Objective:
The aim of this experiment is to provide a powerful and flexible framework for performing complex data
processing and analysis tasks on collections. Aggregation operations allow for the transformation,
grouping, filtering, and computation of data, enabling developers to derive meaningful insights from their
MongoDB data.
Description:
Aggregation operations in MongoDB provide a powerful framework for performing complex data
processing and analysis tasks on collections. These operations allow developers to derive meaningful
insights from their MongoDB data by transforming, grouping, filtering, and computing data in a flexible
and efficient manner.
Pre-Requisites:
This Section contains the list of Software/Tools or required knowledge to complete the task under the
Laboratory Session.
Pre Lab-Task
Answer the following question before entering into lab. The following pre lab task has to perform at home.
In-lab:
Aggregation Operations in MongoDB
Objective: To perform aggregation operations in MongoDB using the MongoDB shell.
Materials:
• MongoDB installed and running (follow the installation steps mentioned earlier)
Procedure:
1. Open the command prompt or PowerShell as an administrator.
2. Navigate to the MongoDB installation directory.
3. Run the mongo command to start the MongoDB shell.
4. By default, the shell connects to the test database. To switch to a different database or create a new
one, use the use command. For example, to switch to a database named mydatabase, enter the
following command:
use mydatabase
5. The shell will output switched to db mydatabase to confirm the database switch.
6. Identify the collection on which you want to perform aggregation operations. For example, consider a
collection named mycollection.
7. Use the aggregation pipeline framework to perform complex data processing and analysis operations
on the collection. The aggregation pipeline consists of multiple stages, each representing a specific
operation.
8. Some common aggregation stages include:
9. Combine multiple stages in the aggregation pipeline to perform complex operations. For example, to
group documents by the "category" field and calculate the average "price" for each category, you can
use the following pipeline:
db.mycollection.aggregate([
{ $group: { _id: "$category", averagePrice: { $avg: "$price" } } }
])
Experiment with different stages and combinations to perform various aggregation operations.
Observations:
Objective: To perform aggregation operations in MongoDB using a MongoDB driver (e.g., pymongo for
Python).
Materials:
• MongoDB installed and running (follow the installation steps mentioned earlier)
• MongoDB driver for your programming language (e.g., pymongo for Python)
Procedure:
1. Install the MongoDB driver for your chosen programming language (e.g., pymongo for Python).
2. Open a text editor or IDE and create a new script file.
3. Import the required MongoDB driver module in your script.
4. Establish a connection to the MongoDB server using the driver's connection methods.
5. Switch to the desired database using the driver's methods (e.g., client.get_database() in
pymongo).
6. Identify the collection on which you want to perform aggregation operations. For example, consider
a collection named mycollection.
7. Use the appropriate method provided by the driver (e.g., db.collection_name.aggregate() in
pymongo) to perform aggregation operations.
8. Construct the aggregation pipeline by specifying the stages and their parameters as a list of
dictionaries or objects. For example, to group documents by the "category" field and calculate the
average "price" for each category, you can use the following code:
pipeline = [
{ "$group": { "_id": "$category", "averagePrice": { "$avg": "$price" } } }
]
cursor = db.collection_name.aggregate(pipeline)
Iterate through the cursor object to retrieve and process the aggregation results.
Experiment with different stages and combinations to perform various aggregation operations.
Observations:
21.Capstone Project-1
22.Capstone Project-2
23.Capstone Project-3
24.Capstone Project-4
There are many types of insurances ranging from health, conveyance, fortuitous, death indemnification, etc.
people enrol in the insurance as per their desideratum and the quantity of the indemnification to be
submitted as premium on a fine-tuned time interval. The agent suggests the client about the types of
insurances and convinces them to cover their indemnification which provides his commission from the
company on a fine-tuned substratum. The online insurance management system provides an online portal
that is beneficial for the client, agents, and even for the company as well. This system maintains the data of
the policy holder, agent information, premium details, and staff record as well. The admin is the
authoritative personnel who takes care of the full-fledged system work condition and provide vital support
throughout the process, he maintains the staff record and data of their circadian work, salary, and leaves
benefits, etc. the agent provides the details of the insurance policies to the customer and enrols him for the
policy as per his need apart from this he is also eligible so that the client pays the premium on time to
perpetuate the policy schedule
25.Capstone Project-5
In most developing countries such as ours, wholesale businesses are still managed using a pen and paper
methodology even with the advent of the age of technology and the internet. This can sometimes lead to
inefficient handling of day-to-day business matters and can also lead to security threats to the business due
to the presence of physical records. This project aims to develop sales management web application for a
wholesale business to Improve the efficiency and security of the business. The lightweight nature of the
web application makes it ideal for small businesses which cannot afford the expensive alternates present in
the market. The Wholesale Management System (WMS) has an administrator login for the wholesaler with
built-in features to keep a check on the sales and the inventory to efficiently run the sales division. The
customers and suppliers of the wholesale business can also be registered to ensure the smooth functioning
of sales. There is also a customer login option which helps the customer in monitoring his purchases from
the wholesaler. By having the above features, the WMS simplifies the daily functioning of the business.
Since many developed countries already use such software to speed up daily business activities, a lot of
information is available in the public domain regarding the desirable structure of such software. We have
used this information to design and model our project.
Features:
26.Capstone Project-6
A General Hospital consists of a number of specialized wards (such as Maternity, Paediatric, Oncology,
etc). Each ward hosts a number of patients, who were admitted on the recommendation of their own GP and
confirmed by a consultant employed by the Hospital. On admission, the personal details of every patient are
recorded. A separate register is to be held to store the information of the tests undertaken and the results of
a prescribed treatment. A number of tests may be conducted for each patient. Each patient is assigned to
one leading consultant but may be examined by another doctor, if required. Doctors are specialists in some
branch of medicine and may be leading consultants for a number of patients, not necessarily from the same
ward.