0% found this document useful (0 votes)
5 views29 pages

Dbms Lab File Mpec

The document outlines a series of experiments related to database management, including installing Oracle, creating entity-relationship diagrams with MySQL Workbench, writing SQL statements, normalizing tables, and implementing cursors, procedures, and triggers in MySQL. Each experiment provides step-by-step instructions and SQL code examples for various database operations. Additionally, it covers the design of a payroll processing system and a library information system using NoSQL (MongoDB).

Uploaded by

manassaxena11
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)
5 views29 pages

Dbms Lab File Mpec

The document outlines a series of experiments related to database management, including installing Oracle, creating entity-relationship diagrams with MySQL Workbench, writing SQL statements, normalizing tables, and implementing cursors, procedures, and triggers in MySQL. Each experiment provides step-by-step instructions and SQL code examples for various database operations. Additionally, it covers the design of a payroll processing system and a library information system using NoSQL (MongoDB).

Uploaded by

manassaxena11
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

Experiment: 1

Program Name: Installing Oracle

Theory Concept: To install the software, we must use the Universal installer.

Implementation:

1. For this installation, we need either the DVDs or a downloaded version of the DVDs. Here,
we install from the downloaded version. From the directory where the DVD files were
unzipped, open Windows Explorer and double-click on [Link] from the \db\Disk1
directory.

2. The product you want to install is Database 11g. Make sure the product is selected and
click Next.

3. Enter orcl for the Global Database Name and for Database Password and Confirm Password.
Then, click Next

Department of Computer Science and Engineering BCS551


4. Configuration Manager allows us to associate our configuration information with our
Meta link account. We can choose to enable it on this window. Then, click Next.

Department of Computer Science and Engineering BCS551


5. Review the Summary window to verify what is to be installed. Then, click Install.

6. The progress window appears.

Department of Computer Science and Engineering BCS551


7. The Configuration Assistants window appears.

8. Our database is now being created.

Department of Computer Science and Engineering BCS551


9. When the database has been created, We can unlock the users you want to use. Click OK.

10. Click Exit. Click Yes to confirm exit.

Department of Computer Science and Engineering BCS551


Experiment: 2

Program Name: Creating Entity-Relationship Diagram using case tools.

Steps:

Step 1: Install MySQL Workbench

We can download it from the official MySQL website:


[Link]

Step 2: Launch MySQL Workbench

After installation, launch MySQL Workbench on computer.

Step 3: Create a New EER Diagram

Click on "File" in the menu bar.


Select "New Model" to create a new Entity-Relationship Diagram (ERD).

Step 4: Add Entities and Attributes

In the diagram canvas, we can add entities by clicking on the "Entity" button in the toolbar and
then clicking on the canvas to place the entity. Double-click on the entity to give it a name.
To add attributes to an entity, right-click on the entity and select "Add Attribute."

Step 5: Define Relationships

To define relationships between entities, select the "Relationship" tool from the toolbar.
Click on one entity and then click on the related entity to establish a relationship.
Specify the cardinality and other properties of the relationship.

Step 6: Save ERD

To save our work. Click on "File" and then "Save" to save the model.

Step 7: Generate SQL Script (Optional)

MySQL Workbench allows us to generate SQL scripts from our ERD. We can do this by clicking
on "Database" and then "Forward Engineer..." to create a database schema based on our ERD.

Step 8: Review and Export (Optional)

We can review our ERD, make any necessary changes, and then export it in different formats,
such as PNG or PDF.

Department of Computer Science and Engineering BCS551


Output Examples:

Department of Computer Science and Engineering BCS551


Department of Computer Science and Engineering BCS551
Department of Computer Science and Engineering BCS551
Department of Computer Science and Engineering BCS551
Department of Computer Science and Engineering BCS551
Department of Computer Science and Engineering BCS551
Experiment: 3
Program Name: Writing SQL statements Using ORACLE /MySQL:

a) Writing basic SQL SELECT statements.


b) Restricting and sorting data.
c) Displaying data from multiple tables.
d) Aggregating data using group function.
e) Manipulating data.
f) Creating and managing tables.

SQL statements using MYSQL:

a) Writing basic SQL SELECT statements.

-- Select all columns from a table


SELECT * FROM employees;

-- Select specific columns from a table


SELECT first_name, last_name FROM employees;

-- Select distinct values from a column


SELECT DISTINCT department_id FROM employees;

-- Select data with a filter (WHERE clause)


SELECT * FROM employees WHERE salary > 50000;

-- Select data with a combination of conditions


SELECT * FROM employees WHERE department_id = 2 AND salary > 50000;

b) Restricting and sorting data.


-- Sorting data in ascending order
SELECT * FROM employees ORDER BY last_name;

-- Sorting data in descending order


SELECT * FROM employees ORDER BY hire_date DESC;

-- Limiting the number of rows returned


SELECT * FROM employees LIMIT 10;

-- Limiting the number of rows with an offset


SELECT * FROM employees LIMIT 10 OFFSET 20;

c) Displaying data from multiple tables (JOIN).

-- Inner Join

SELECT orders.order_id, customers.customer_name


FROM orders
INNER JOIN customers ON orders.customer_id = customers.customer_id;
Department of Computer Science and Engineering BCS551
-- Left Join

SELECT employees.first_name, departments.department_name


FROM employees
LEFT JOIN departments ON employees.department_id = departments.department_id;

d) Aggregating data using group function.

-- Calculate the total salary for each department

SELECT department_id, SUM(salary) AS total_salary


FROM employees
GROUP BY department_id;

-- Calculate the average salary

SELECT AVG(salary) AS average_salary


FROM employees;

e) Manipulating data (INSERT, UPDATE, DELETE)

-- Inserting a new record

INSERT INTO employees (first_name, last_name, salary)


VALUES ('John', 'Doe', 60000);

-- Updating an existing record


UPDATE employees
SET salary = 65000
WHERE employee_id = 101;

-- Deleting a record

DELETE FROM employees


WHERE employee_id = 102;

f) Creating and managing tables:

-- Creating a new table


CREATE TABLE products (
product_id INT PRIMARY KEY,
product_name VARCHAR (255),
price DECIMAL (10, 2)
);
-- Modifying a table (adding a new column)
ALTER TABLE employees
ADD COLUMN email VARCHAR (255);

-- Dropping a table
DROP TABLE products;
Department of Computer Science and Engineering BCS551
Experiment: 4

1. Program Name: Create the unnormalized table and normalized above table by using SQL query.

Theory Concept:

Normalization is a database design process used to organize data in a relational database efficiently
and reduce data redundancy. It is a multi-step process that sets the data into tabular form and removes the
duplicated data from the relational tables. Normalization typically involves dividing a database into two or
more tables and defining relationships between them. Let's go through an example of normalizing a
database with sample data and MySQL queries. We'll start with an unnormalized table and normalize it
step by step.

Step 1: Create an Unnormalized Table


Suppose we have a table called "CustomerOrders" that stores information about customers and their
orders. This table is not normalized because it contains repeating groups and data redundancy:

CREATE TABLE CustomerOrders (


customer_id INT PRIMARY KEY,
customer_name VARCHAR(255),
order_id INT,
order_date DATE,
total_amount DECIMAL(10, 2)
);

INSERT INTO CustomerOrders (customer_id, customer_name, order_id, order_date, total_amount)


VALUES
(1, 'Alice', 101, '2023-01-15', 100.00),
(1, 'Alice', 102, '2023-02-20', 150.00),
(2, 'Bob', 201, '2023-03-10', 75.50),
(3, 'Charlie', 301, '2023-04-05', 200.00);

Step 2: Normalize the Data


We'll normalize the data by creating two separate tables: "Customers" and "Orders." The "Customers"
table will store customer information, and the "Orders" table will store order information.

-- Create the Customers table


CREATE TABLE Customers (
customer_id INT PRIMARY KEY,
customer_name VARCHAR(255)
);
-- Create the Orders table
CREATE TABLE Orders (
order_id INT PRIMARY KEY,
customer_id INT,
order_date DATE,
total_amount DECIMAL(10, 2),
FOREIGN KEY (customer_id) REFERENCES Customers(customer_id)
);

Department of Computer Science and Engineering BCS551


➢ Populate the Customers table with customer information

INSERT INTO Customers (customer_id, customer_name)


SELECT DISTINCT customer_id, customer_name FROM CustomerOrders;

➢ Populate the Orders table with order information

INSERT INTO Orders (order_id, customer_id, order_date, total_amount)


SELECT order_id, customer_id, order_date, total_amount FROM CustomerOrders;

Step 3: Query the Normalized Tables

Now that we have normalized our data, we can query the "Customers" and "Orders" tables to
retrieve information:

➢ Query to retrieve customer information

SELECT * FROM Customers;

➢ Query to retrieve order information

SELECT * FROM Orders;

➢ Query to retrieve customer names and their total order amounts

SELECT c.customer_name, SUM(o.total_amount) AS total_order_amount


FROM Customers c
JOIN Orders o ON c.customer_id = o.customer_id
GROUP BY c.customer_name;

Output:

These queries demonstrate the result of normalizing the data. The "Customers" table contains
unique customer information, and the "Orders" table stores order details with a reference to the customer.
The last query retrieves the total order amount for each customer, demonstrating the power of relational
databases and normalization.

Department of Computer Science and Engineering BCS551


Experiment: 5

Program Name: Creating cursor in MySQL.

Theory Concept: A cursor is a database object that allows us to retrieve rows from a result set one at
a time, instead of processing the entire set at [Link] is useful when you need to perform row-level
operations such as calculations, conditional logic, or iterative updates.

Types of Cursors:
1. Implicit Cursor: Automatically created by MySQL for single-row queries.
2. Explicit Cursor: Declared by the user to handle query results manually.

SQL Implementation:
Step 1 – Create Base Table

CREATE TABLE EMPLOYEE (


EmpID INT PRIMARY KEY,
EmpName VARCHAR(50),
Salary DECIMAL(10,2)
);
Step 2 – Insert values in Base Table

INSERT INTO EMPLOYEE VALUES


(1, 'Amit', 45000.00),
(2, 'Neha', 52000.00),
(3, 'Ravi', 60000.00),
(4, 'Priya', 40000.00);

Step 3 – Create Cursor

CREATE PROCEDURE DisplayEmployeeSalary()


BEGIN
DECLARE done INT DEFAULT 0;
DECLARE eName VARCHAR(50);
DECLARE eSalary DECIMAL(10,2);

DECLARE emp_cursor CURSOR FOR SELECT EmpName, Salary FROM EMPLOYEE;


DECLARE CONTINUE HANDLER FOR NOT FOUND SET done = 1;

OPEN emp_cursor;

read_loop: LOOP
FETCH emp_cursor INTO eName, eSalary;
IF done THEN
LEAVE read_loop;
END IF;
SELECT CONCAT('Employee: ', eName, ' | Salary: ', eSalary) AS Output;
END LOOP;

Department of Computer Science and Engineering BCS551


CLOSE emp_cursor;
END

Step 3 – Execute Procedure


CALL DisplayEmployeeSalary();

Output
Employee: Amit
Employee: Neha
Employee: Ravi
Employee: Priya

Department of Computer Science and Engineering BCS551


Experiment: 6

Program Name: Creating procedure and functions in MySQL.

Theory Concept:
A stored procedure is a set of SQL statements stored in the database that can be executed
repeatedly. A function is similar but returns a value and is generally used in SQL expressions.

SQL Implementation:
Example 1 – Stored Procedure

CREATE PROCEDURE GetStudentMarks(IN stu_id VARCHAR(10))


BEGIN
SELECT StudentName, Marks
FROM ENROLLMENT
WHERE StudentID = stu_id;
END
CALL GetStudentMarks('S01');

Output
StudentName Marks
Rahul 85
Rahul 90

Example 2 – Function

CREATE FUNCTION TotalMarks (stu_id VARCHAR(10)) RETURNS INT


BEGIN
DECLARE total INT;
SELECT SUM(Marks) INTO total FROM ENROLLMENT WHERE StudentID = stu_id;
RETURN total;
END
SELECT TotalMarks('S01') AS 'Total Marks';

Output
TotalMarks
175
Result:
Stored procedures and functions were successfully created and executed in MySQL.

Department of Computer Science and Engineering BCS551


Experiment: 7

Program Name: Creating packages and triggers in MySQL.

Theory Concept:

A trigger is a stored program that automatically executes when a specific event occurs in a table —
such as INSERT, UPDATE, or DELETE.

Implementation:

Example 1 – Before Insert Trigger

DELIMITER //
CREATE TRIGGER before_student_insert
BEFORE INSERT ON STUDENT
FOR EACH ROW
BEGIN
IF [Link] IS NULL THEN
SET [Link] = 'Unknown';
END IF;
END //
DELIMITER ;
Example 2 – After Update Trigger (Audit)

CREATE TABLE Audit_Log (


LogID INT AUTO_INCREMENT PRIMARY KEY,
StudentID VARCHAR(10),
OldMarks INT,
NewMarks INT,
ActionTime TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);

DELIMITER //
CREATE TRIGGER after_marks_update
AFTER UPDATE ON ENROLLMENT
FOR EACH ROW
BEGIN
INSERT INTO Audit_Log(StudentID, OldMarks, NewMarks)
VALUES ([Link], [Link], [Link]);
END //
DELIMITER;
Output:
Whenever a student’s marks are updated, a record is added to Audit_Log.

StudentID OldMarks NewMarks ActionTime


S01 85 90 2025-10-05 11:45:00

Department of Computer Science and Engineering BCS551


Experiment: 8

Program Name: Design and implementation of payroll processing system.

Theory Concept:
A Payroll System manages employee details, salaries, deductions, and net pay. The design ensures
correct computation of total salary and record management.

Relationships:
One Department → Many Employees
One Employee → One Salary record

SQL Implementation:

CREATE TABLE Department (


DeptID INT PRIMARY KEY,
DeptName VARCHAR(50)
);

CREATE TABLE Employee (


EmpID INT PRIMARY KEY,
EmpName VARCHAR(50),
DeptID INT,
FOREIGN KEY (DeptID) REFERENCES Department(DeptID)
);

CREATE TABLE Salary (


EmpID INT,
BasicPay DECIMAL(10,2),
Deductions DECIMAL(10,2),
NetPay DECIMAL(10,2),
FOREIGN KEY (EmpID) REFERENCES Employee(EmpID)
);

INSERT INTO Department VALUES (1, 'IT'), (2, 'HR');


INSERT INTO Employee VALUES (101, 'Ravi', 1), (102, 'Neha', 2);
INSERT INTO Salary VALUES (101, 50000, 5000, 45000), (102, 40000, 2000, 38000);

Output:

EmpID EmpName DeptName BasicPay Deductions NetPay


101 Ravi IT 50000 5000 45000
102 Neha HR 40000 2000 38000

Department of Computer Science and Engineering BCS551


Experiment: 9
Program Name: To design and implement a Library Information System using NoSQL (MongoDB) to
store and manage book, member, and issue-return details efficiently.

Theory Concept:
ALGORITHM-
1. Create a MongoDB database libraryDB.
2. Create collections:
i. books— store book details
ii. members— store library member details
iii. issued_books— store issue/return records
3. Insert sample documents.
4. Perform CRUD operations and queries.

CODE:

use libraryDB
[Link]([
{ book_id: 1, title: "Database System Concepts", author: "Korth", category: "Database",
available: true },
{ book_id: 2, title: "Artificial Intelligence", author: "Russell", category: "AI", available: true },
{ book_id: 3, title: "Operating Systems", author: "Silberschatz", category: "OS", available:
false }
])
[Link]([
{ member_id: 101, name: "Lakshmi", email: "lakshmi@[Link]" },
{ member_id: 102, name: "Rahul", email: "rahul@[Link]" }
])
db.issued_books.insertOne({ issue_id: 1,
book_id: 3, member_id: 101, issue_date: "2025-10-25", return_date: null })
[Link]()
[Link]()
db.issued_books.find()

Department of Computer Science and Engineering BCS551


Output:
switched to db libraryDB
{
"acknowledged" : true, "insertedIds" : [
ObjectId("69033f97af964449bccd3e4f"),
ObjectId("69033f97af964449bccd3e50"),
ObjectId("69033f97af964449bccd3e51")
]
}

{
"acknowledged" : true, "insertedIds" : [
ObjectId("69033f97af964449bccd3e52"), ObjectId("69033f97af964449bccd3e53")
]
}
{
"acknowledged" : true,
"insertedId" : ObjectId("69033f97af964449bccd3e54")
}
{ "_id" : ObjectId("69033f97af964449bccd3e4f"), "book_id" : 1, "title" : "Database System Concepts",
"author" : "Korth", "category" : "Database", "available" : true }
{ "_id" : ObjectId("69033f97af964449bccd3e50"), "book_id" : 2, "title" : "Artificial
Intelligence", "author" : "Russell", "category" : "AI", "available" : true }
{ "_id" : ObjectId("69033f97af964449bccd3e51"), "book_id" : 3, "title" : "Operating Systems",
"author" : "Silberschatz", "category" : "OS", "available" : false }
{ "_id" : ObjectId("69033f97af964449bccd3e52"), "member_id" : 101, "name" : "Lakshmi", "email" :
"lakshmi@[Link]" }
{ "_id" : ObjectId("69033f97af964449bccd3e53"), "member_id" : 102, "name" : "Rahul", "email" :
"rahul@[Link]" }
{ "_id": ObjectId("69033f97af964449bccd3e54"), "issue_id": 1, "book_id": 3, "member_id" : 101,
"issue_date" : "2025-10-25", "return_date" : null }

Department of Computer Science and Engineering BCS551


Experiment: 10

Program Name: Design and implementation of Student Information System

Theory Concept:

Designing and implementing a Student Information System (SIS) experiment in a Database


Management System (DBMS) is a practical way to learn about database design and development. Below, I’ll
outline a simplified experiment scenario for creating a basic SIS using a relational DBMS (e.g., MySQL,
PostgreSQL). This experiment assumes you have basic knowledge of SQL and database concepts.

Experiment Scenario:

Creating a Student Information System (SIS) for a university. The system should store information
about students, courses, and grades. Students can enroll in courses, and teachers can enter grades for students
in those courses.

Experiment Steps:

1. Database Design:
Define the database schema with tables for students, courses, and grades. Here's a simplified schema:

-- Students table
CREATE TABLE students (
student_id INT PRIMARY KEY,
first_name VARCHAR(50),
last_name VARCHAR(50),
birthdate DATE,
email VARCHAR(100)
);

-- Courses table
CREATE TABLE courses (
course_id INT PRIMARY KEY,
course_name VARCHAR(100),
teacher VARCHAR(100)
);

-- Grades table
CREATE TABLE grades (
grade_id INT PRIMARY KEY,
student_id INT,
course_id INT,
grade VARCHAR(2),
FOREIGN KEY (student_id) REFERENCES students(student_id),
FOREIGN KEY (course_id) REFERENCES courses(course_id)
);

Department of Computer Science and Engineering BCS551


2. Data Population:
Insert sample data into the tables for testing purposes.

-- Insert sample students


INSERT INTO students (student_id, first_name, last_name, birthdate, email) VALUES (1, 'John',
'Doe', '1995-01-15', 'john@[Link]'), (2, 'Jane', 'Smith', '1996-03-22', 'jane@[Link]');
-- Insert sample courses
INSERT INTO courses (course_id, course_name, teacher) VALUES (101, 'Mathematics 101', 'Dr.
Smith'), (102, 'Computer Science 101', 'Prof. Johnson');
-- Enroll students in courses
INSERT INTO grades (student_id, course_id, grade) VALUES (1, 101, 'A'), (1, 102, 'B'), (2, 101, 'B');

3. Querying the Database:

Practice querying the database to retrieve information. For example, we


can retrieve a student's grades or find courses taught by a specific teacher.

-- Get a student's grades


SELECT s.first_name, s.last_name, c.course_name, [Link]
FROM students s
JOIN grades g ON s.student_id = g.student_id
JOIN courses c ON g.course_id = c.course_id
WHERE s.student_id = 1;

-- Find courses taught by a specific teacher


SELECT course_name
FROM courses
WHERE teacher = 'Dr. Smith';

4. CRUD Operations:

Practice performing CRUD (Create, Read, Update, Delete) operations on the database. For example,
we can add a new student, update a student's information, or delete a course.

-- Create: Add a new student


INSERT INTO students (student_id, first_name, last_name, birthdate, email)
VALUES (3, 'Alice', 'Johnson', '1997-05-10', 'alice@[Link]');
-- Update: Change a student's email
UPDATE students
SET email = 'new_email@[Link]'
WHERE student_id = 3;

-- Delete: Remove a course


DELETE FROM courses
WHERE course_id = 102;

Department of Computer Science and Engineering BCS551


Experiment: 11

Program Name: To develop a NoSQL-based system for automatic backup and recovery of file
metadata using MongoDB.

Theory Concept:

ALGORITHM:

1. Create a database backupDB


2. Create collections files, backups, and recovered.
3. Insert metadata of files into files.
4. Copy records into backups(simulate backup).
5. Copy back to recovered(simulate recovery).

IMPLEMENTATION:

use backupDB
[Link]([
{ file_id: 1, file_name: "[Link]", path: "/docs/[Link]", size: "200KB", last_modified:
"2025-10-25" },
{ file_id: 2, file_name: "[Link]", path: "/data/[Link]", size: "500KB", last_modified: "2025-
10-26" }
])
[Link]([Link]().toArray())
[Link]([Link]({ file_id: 1 })) [Link]()
[Link]()
[Link]()

Department of Computer Science and Engineering BCS551


Output:
switched to db backupDB
{
"acknowledged" : true, "insertedIds" : [
ObjectId("6903414fd9098b4e4044adfd"), ObjectId("6903414fd9098b4e4044adfe")
]
}
{
"acknowledged" : true, "insertedIds" : [
ObjectId("6903414fd9098b4e4044adfd"), ObjectId("6903414fd9098b4e4044adfe")
]
}
{
"acknowledged" : true,
"insertedId" : ObjectId("6903414fd9098b4e4044adfd")
}
{ "_id" : ObjectId("6903414fd9098b4e4044adfd"), "file_id" : 1, "file_name" : "[Link]", "path" :
"/docs/[Link]", "size" : "200KB", "last_modified" : "2025-10-25" }
{ "_id" : ObjectId("6903414fd9098b4e4044adfe"), "file_id" : 2, "file_name" : "[Link]", "path" :
"/data/[Link]", "size" : "500KB", "last_modified" : "2025-10-26" }
{ "_id" : ObjectId("6903414fd9098b4e4044adfd"), "file_id" : 1, "file_name" : "[Link]", "path" :
"/docs/[Link]", "size" : "200KB", "last_modified" : "2025-10-25" }
{ "_id" : ObjectId("6903414fd9098b4e4044adfe"), "file_id" : 2, "file_name" : "[Link]", "path" :
"/data/[Link]", "size" : "500KB", "last_modified" : "2025-10-26" }
{ "_id" : ObjectId("6903414fd9098b4e4044adfd"), "file_id" : 1, "file_name" : "[Link]", "path" :
"/docs/[Link]", "size" : "200KB", "last_modified" : "2025-10-25" }

Department of Computer Science and Engineering BCS551


Experiment: 12 (C)

Program Name: To design and implement a Hospital Management System using MongoDB
(NoSQL) for managing patient, doctor, and appointment information efficiently.

Theory Concept:

ALGORITHM:

1. Create a new database hospitalDB.


2. Create three collections:
a. patients— stores patient details.
b. doctors— stores doctor details.
c. appointments— stores appointment details.
3. Insert sample data into each collection.
4. Perform basic retrieval operations using find().
5. Test queries like joining doctor–patient details using $lookup

CODE:
use hospitalDB
[Link]([
{ pid: 1, name: "Ananya Sharma", age: 32, gender: "Female", disease: "Flu", admitted: true },
{ pid: 2, name: "Rohit Verma", age: 45, gender: "Male", disease: "Diabetes", admitted: false
},
{ pid: 3, name: "Lakshmi Prasad", age: 28, gender: "Male", disease: "Asthma", admitted: true }
])
[Link]([
{ did: 101, name: "Dr. Neha Singh", specialization: "General Physician" },
{ did: 102, name: "Dr. Rajiv Kumar", specialization: "Cardiologist"},
{ did: 103, name: "Dr. Shalini Das", specialization: "Pulmonologist"} ])
[Link]([
{ app_id: 1, pid: 1, did: 101, date: "2025-10-25", time: "10:30 AM"},
{ app_id: 2, pid: 2, did: 102, date: "2025-10-26", time: "02:00 PM"},
{ app_id: 3, pid: 3, did: 103, date: "2025-10-27", time: "11:15 AM" } ])
[Link]() [Link]()
[Link]()
[Link]([
{
$lookup: {
from: "patients", localField: "pid", foreignField: "pid", as: "patient_info"},
{
$lookup: {
from: "doctors", localField: "did", foreignField: "did", as: "doctor_info"}} ])
Department of Computer Science and Engineering BCS551
Output:
switched to db hospitalDB
{
"acknowledged" : true, "insertedIds": [
ObjectId("6903430ef8370f7484cc4e38"),
ObjectId("6903430ef8370f7484cc4e39"),
ObjectId("6903430ef8370f7484cc4e3a")]
}
{
"acknowledged" : true, "insertedIds": [
ObjectId("6903430ef8370f7484cc4e3b"),
ObjectId("6903430ef8370f7484cc4e3c"),
ObjectId("6903430ef8370f7484cc4e3d")]
}
{
"acknowledged" : true, "insertedIds": [
ObjectId("6903430ef8370f7484cc4e3e"),
ObjectId("6903430ef8370f7484cc4e3f"),
ObjectId("6903430ef8370f7484cc4e40")]
}
{ "_id" : ObjectId("6903430ef8370f7484cc4e38"), "pid" : 1, "name" : "Ananya Sharma", "age" : 32, "gender" :
"Female", "disease" : "Flu", "admitted" : true }
{ "_id" : ObjectId("6903430ef8370f7484cc4e39"), "pid" : 2, "name" : "Rohit Verma", "age" : 45, "gender" : "Male",
"disease" : "Diabetes", "admitted" : false }
{ "_id" : ObjectId("6903430ef8370f7484cc4e3a"), "pid" : 3, "name" : "Lakshmi Prasad", "age" : 28, "gender" : "Male",
"disease" : "Asthma", "admitted" : true }
{ "_id" : ObjectId("6903430ef8370f7484cc4e3b"), "did" : 101, "name" : "Dr. Neha Singh", "specialization" : "General
Physician" }
{ "_id" : ObjectId("6903430ef8370f7484cc4e3c"), "did" : 102, "name" : "Dr. Rajiv Kumar", "specialization" :
"Cardiologist" }
{ "_id" : ObjectId("6903430ef8370f7484cc4e3d"), "did" : 103, "name" : "Dr. Shalini Das", "specialization" :
"Pulmonologist" }
{ "_id" : ObjectId("6903430ef8370f7484cc4e3e"), "app_id" : 1, "pid" : 1, "did" : 101, "date" : "2025-10-25", "time" :
"10:30 AM" }
{ "_id" : ObjectId("6903430ef8370f7484cc4e3f"), "app_id" : 2, "pid" : 2, "did" : 102, "date" : "2025-10-26", "time" :
"02:00 PM" }
{ "_id" : ObjectId("6903430ef8370f7484cc4e40"), "app_id" : 3, "pid" : 3, "did" : 103, "date" : "2025-10-27", "time" :
"11:15 AM" }
{ "_id" : ObjectId("6903430ef8370f7484cc4e3e"), "app_id" : 1, "pid" : 1, "did" : 101, "date" : "2025-10-25", "time" :
"10:30 AM", "patient_info" : [ { "_id" : ObjectId("6903430ef8370f7484cc4e38"), "pid" : 1, "name" : "Ananya
Sharma", "age" : 32, "gender" : "Female", "disease" : "Flu", "admitted" : true } ], "doctor_info" : [ { "_id" :
ObjectId("6903430ef8370f7484cc4e3b"), "did" : 101, "name" : "Dr. Neha Singh", "specialization" : "General
Physician" } ] }
{ "_id" : ObjectId("6903430ef8370f7484cc4e3f"), "app_id" : 2, "pid" : 2, "did" : 102, "date" : "2025-10-26", "time" :
"02:00 PM", "patient_info" : [ { "_id" : ObjectId("6903430ef8370f7484cc4e39"), "pid" : 2, "name" : "Rohit Verma",
"age" : 45, "gender" : "Male", "disease" : "Diabetes", "admitted" : false } ], "doctor_info" : [ { "_id" :
ObjectId("6903430ef8370f7484cc4e3c"), "did" : 102, "name" : "Dr. Rajiv Kumar", "specialization" : "Cardiologist" }
]}
{ "_id" : ObjectId("6903430ef8370f7484cc4e40"), "app_id" : 3, "pid" : 3, "did" : 103, "date" : "2025-10-27", "time" :
"11:15 AM", "patient_info" : [ { "_id" : ObjectId("6903430ef8370f7484cc4e3a"), "pid" : 3, "name" : "Lakshmi
Prasad", "age": 28, "gender" : "Male", "disease" : "Asthma", "admitted" : true } ], "doctor_info" : [ {
"_id" : ObjectId("6903430ef8370f7484cc4e3d"), "did" : 103, "name" : "Dr. Shalini Das", "specialization":
"Pulmonologist" } ] }
Department of Computer Science and Engineering BCS551

You might also like