0% found this document useful (0 votes)
2 views

Lab Manual PS2

The document outlines the Programming Skills Lab II (CS410) course for the Computer Science and Engineering Department at P. R. Pote Patil College of Engineering & Management for the academic year 2024-25. It includes the institute's vision and mission, program outcomes, educational objectives, practical guidelines for teachers and students, and a list of practicals related to NodeJS and MongoDB. The document emphasizes the importance of hands-on skills, ethical practices, and continuous assessment in the learning process.
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views

Lab Manual PS2

The document outlines the Programming Skills Lab II (CS410) course for the Computer Science and Engineering Department at P. R. Pote Patil College of Engineering & Management for the academic year 2024-25. It includes the institute's vision and mission, program outcomes, educational objectives, practical guidelines for teachers and students, and a list of practicals related to NodeJS and MongoDB. The document emphasizes the importance of hands-on skills, ethical practices, and continuous assessment in the learning process.
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 38

P. R.

POTE PATIL

College of Engineering & Management, Amravati.

DEPARTMENT OF COMPUTER SCIENCE & ENGINEERING

Year: 2024-25 Semester: IV

Course: Programming Skills Lab II(MongoDB & NodeJS)


(CS410)
Programming skill Lab II (CS410)

Computer Science and Engineering Department


Programming skill Lab II (CS410)

Institute Vision Mission


Vision
To flourish as a center of excellence for producing the skilled
technocrats and committed human beings.
Mission

 To create conducive environment for teaching &learning.

 To impart quality education through demanding academic


programs.

 To enhance career opportunities by exposure to Industries & recent


technologies.

 To develop professionals with strong ethics and human values for


the betterment of society.

Department of Computer Science and Engineering


Vision
To achieve Excellence in Computer Science and engineering for serving
the growing needs of the software industry and society
Mission
M1- To Create an ambiance that shall foster the growth for
developing innovative and entrepreneurial skills.

M2- To identify areas of specialization upon which the department


can concentrate, thus promote academic growth and career
opportunities.

M3- To develop human resources with ethical and moral values for
overall personality development to serve the society.

Computer Science and Engineering Department


Programming skill Lab II (CS410)

Program Outcomes:
Engineering Graduate will be able to:
1. Engineering Knowledge: Apply the knowledge of mathematics,
science, engineering fundamentals, and an engineering specialization
to the solution of complex engineering problems.
2. Problem Analysis: Identify, formulate, research literature, and
analyze complex engineering problems reaching substantiated
conclusions using first principles of mathematics, natural sciences, and
engineering sciences.
3. Design /development of solutions: Design solutions for complex
engineering problems and design system components or processes
that meet the specified needs with appropriate consideration for the
public health and safety, and the cultural, societal, and environmental
considerations.
4. Conduct investigations of complex problems: Use research-based
knowledge and research methods including design of experiments,
analysis and interpretation of data, and synthesis of the information to
provide valid conclusions.
5. Modern tool usage: Create, select, and apply appropriate techniques,
resources, and modern engineering and IT tools including prediction
and modeling to complex engineering activities with an understanding
of the limitations.
6. The engineer and society: Apply reasoning informed by the
contextual knowledge to assess societal, health, safety, legal and
cultural issues and the consequent responsibilities relevant to the
professional engineering practice.
7. Environment and sustainability: Understand the impact of the
professional engineering solutions in societal and environmental
contexts, and demonstrate the knowledge of, and need for sustainable
development.
8. Ethics: Apply ethical principles and commit to professional ethics and
responsibilities and norms of the engineering practice.
9. Individual and team work: Function effectively as an individual, and
as a member or leader in diverse teams, and in multidisciplinary
settings.
10. Communication: Communicate effectively on complex engineering
activities with the engineering community and with society at large,
such as, being able to comprehend and write effective reports and
design documentation, make effective presentations, and give and
receive clear instructions.
11. Project management and finance: Demonstrate knowledge and

Computer Science and Engineering Department


Programming skill Lab II (CS410)

understanding of the engineering and management principles and


apply these to one’s own work, as a member and leader in a team, to
manage projects and in multidisciplinary environments.
12. Life-long learning: Recognize the need for, and have the
preparation and ability to engage in independent and life-long learning
in the broadest context of technological change.

Program Educational Objectives (PEOs)

⮚ Preparation: To prepare graduates to have knowledge of computer

science and competency for careers in industry.

⮚ Core Competence: To develop problem solving skills in to the

graduates that are required to analyse, design and implement

solution with the computer knowledge.

⮚ Breadth: To nurture the graduates to be an effective team member,

build proficiency in soft skills, inculcate multidisciplinary approach

and the ability to relate engineering with social context.

⮚ Professional and Lifelong Learning: To inculcate ethical practices,

professionalism and environmental awareness for sustainable

development among students with an attitude towards lifelong

learning.

PSO:

⮚ PSO1 : System Development : Apply knowledge of computer science

and principals of software design in building the software or

hardware projects.

⮚ PSO2 : Problem Solving Ability :Use knowledge of various domains

Computer Science and Engineering Department


Programming skill Lab II (CS410)

to implement innovative solutions to cater the needs of industry and

business following ethical values

GUIDELINES FOR TEACHERS

Teachers shall discuss the following points with students before start of
practical of the subject.
1. Learning Overview: To develop better understanding of importance of the

subject. To know related skills to be developed such as intellectual and motor

skills.

2. Know your Laboratory Work: To understand the layout of laboratory,

specifications of equipment / instruments /materials, procedure, working in

groups, planning time etc. also to know total amount of work to be done in

the laboratory.

3. Teacher shall ensure that required equipment is in working condition before

start of each experiment, also keep operating instruction manual available.

4. Explain prior concepts to the students before starting of each experiment.

5. Evolve student’s activity at the time of conduct of each experiment.

6. While taking reading / observation each student (from batch of 20 students)

shall be given a chance to perform / observe the experiment.

7. Teacher shall assess the performance of students continuously.

8. Teacher is expected to share the skills to be developed in the students.

9. Teacher should ensure that the respective skills are developed in the

students after the completion of the practical exercise.

10.Teacher may provide additional knowledge and skills to the students even

though not covered in the manual but are expected from students by the

Computer Science and Engineering Department


Programming skill Lab II (CS410)

industries.

11.Teacher may suggest the students to refer additional related literature of the

technical papers / reference books / Seminar Proceedings, etc.

12.Focus should be given on development of enlisted skills rather than

theoretical / codified knowledge.

13.During assessment teacher is expected to ask questions to the students to

tap their achievements regarding related knowledge and skills.

14.Teacher should give more focus on hands on skills.

INSTRUCTIONS FOR STUDENTS

1. Students shall read the points given below for understanding the theoretical
concepts and practical applications.
2. Listen carefully to the lecture given by teacher about importance of subject,
curriculum philosophy, learning structure, skills to be developed, information
about equipment, instruments, procedure, method of continuous
assessment, tentative plan of work in laboratory and total amount of works
to be done in a semester.
3. Student shall undergo study visit of the laboratory for types of equipment,
and material to be used, before performing experiments.
4. Read the write up of each experiment to be performed, a day in advance.
5. Organize the work in the group and make a record of all observations.
6. Understand the purpose of experiment and its practical implications.
7. Student should not hesitate to ask any difficulty faced during conduct of
practical /exercise.
8. Write the answers of the questions allotted by the teacher during practical
hours if possible or afterwards, but immediately.
9. Student should develop the habit of pear discussion / group discussion
related to experiments / exercise so that exchanges of knowledge / skills
could take place.
10.Students shall attempt to develop related hands-on-skills and gain
confidence.
11.Student shall focus on development of skills rather than theoretical or
codified knowledge.

Computer Science and Engineering Department


Programming skill Lab II (CS410)

12.Student shall insist for the completions of recommended Laboratory Work,


answers to the given question etc.
13.Student shall develop the habit of evolving more ideas, innovations, skills
etc. that included in the scope of the manual.
14.Student shall refer technical magazines, proceedings of the Seminars, refer
website related to the scope of the subjects and update their knowledge and
skills.
15.Student should develop the habit of not depend totally on teachers but to
develop self-learning techniques.
16.Student should develop the habit to interact with the teacher without
hesitation with respect to academic involved.
17.Student should develop habit to submit the practical’s exercise continuously
and progressively on the schedule dates and should get the assessment
done.
18.Student should be well prepared while submitting the write up of the
exercise. This will develop the continuity of the studies and he will not be
overloaded at the end of the term.

P. R. POTE PATIL
COLLEGE OF ENGINEERING & MANAGEMENT, AMRAVATI.

DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING

Certificate

This is to certify that Mr./ Ms …………………………………………...

of ….... Semester of Bachelor of Technology in Computer

Science and Engineering of P. R. Pote Patil College of

Engineering & Management, Amravati, has completed the

Computer Science and Engineering Department


Programming skill Lab II (CS410)

term work satisfactory of course …………………. for the

academic year 20 - 20 as prescribed in the curriculum.

Date………………… Roll No……………………

Head of the
Subject Teacher
Department

LIST OF (PRACTICALS / EXPERIMENTS) & PROGRESSIVE ASSESSMENT FOR TERM WORK

Academic Year :2024-25 Course: Programming Skill Lab II


Course Code: CS410 Semester: IV

Name of Faculty: ______________________________

Name of Student: ______________________________

Roll No _____________________
Date of Date of
Title of the Sign of
SN. Performanc Submissio
Practical / Experiment Teacher
e n
Explore the concept of NodeJS & Setup
1 its environment for development. Run
a Node Js program to print ‘Hello world’
Accomplish the concept of HTTP
2
module & Run a program in NodeJS.
Perform various operations like create,
3 update, rename & delete using file
system Module in NodeJS
4 Execute the concept of URL Module .

Computer Science and Engineering Department


Programming skill Lab II (CS410)

Run a program to split a web address


into readable parts using url.parse()
method
Implement NodeJS event module . Run
5 a NodeJS program using EventEmitter
class
Explore the database MongoDB &
setup its environment for
development. Create a MongoDB
6
document using fields numbers,
strings, boolean, arrays, or even
nested documents.
Develop a database & collection using
7
NodeJS & MongoDB.
Apply Insert operation in MongoDB to
8 insert a document into collection &
run a program into NodeJS.
Implement delete operation in
9 MongoDB to delete a record from
collection & run a program in NodeJS.
Compile a NodeJS program to update
1
the record in collection in MongoDB
0
using UpdateOne() command.

Signature of Faculty

Computer Science and Engineering Department


Programming skill Lab II (CS410)

Course Outcomes
S
Outcomes
N
After successful completion of laboratory course, the students will able to

1 Examine various Node.js core modules, including HTTP, File System, URL, and
Event modules.
2 Implement Node.js modules to establish HTTP servers, process URLs, and
manipulate files dynamically
3 Assess and troubleshoot the setup and configuration of Node.js and MongoDB
environments
4 Develop and execute Node.js programs for file system operations, CRUD in
MongoDB, and event handling.
5 Integrate MongoDB with Node.js to design and manage a database with CRUD
operations efficiently.

Rubrics used for continuous Assessment in every lab session

Allocate
Skills Parameters High Medium Low
d Marks
1. Handle equipment/
Most Partially Below
tools/ commands
satisfactory successful expectation
correctly or Logic
(4-5) (3) (0-2)
Formation (5)
Exceptional Satisfactor Unsatisfactory
2. Work cohesively in
(2) y (1) (0)
Proces team (2)
s Partially
15
Relate 1. Integrate system & correct (2- Incorrect or
d Skills measure parameters Highly 3) unsatisfactory
correctly or Debugging satisfactory (0-1)
Ability (4) (4) *Complete *Completed
2. Completed experiment In time (4) d but with 50%
as per schedule (4) delayed delayed (1)
(2)
Partially
Obtain correct results, Highly
correct (2- Incorrect (0-1)
Interpret results (4) Accurate (4)
Produc 3)
t Highly Partially Unsatisfactory
Draw conclusion (3)
Relate 10 accurate (3) (2) (1)
d Skills Answer practical related
Highly Moderate
questions & submit the Unsatisfactory
satisfactory satisfactor
write up of expt on time (1)
(3) y (2)
(3)

Total Marks 25 Marks

Computer Science and Engineering Department


Programming skill Lab II (CS410)

Assessment

Marks Rubrics: 25 = a (07) + b (04) + c (04) + d (04) + e (03) + f (03)


a: Handle equipment/ tools/ commands correctly & safely/ Logic Formation
b: Integrate system & measure parameters correctly or Debugging Ability
c: Completed experiment as per schedule
d: Obtain correct results, Interpret results
e: Draw conclusion
f: Answer practical related questions & submit the write up of experiment
on time

Title of the (a) (b) (c) (d) (e) (f) Total


S.N.
Practical / Experiment 07 04 04 04 03 03 25 Marks
Explore the concept of NodeJS & Setup its
01 environment for development. Run a Node Js
program to print ‘Hello world’
Accomplish the concept of HTTP module & Run
02
a program in NodeJS.
Perform various operations like create, update,
03 rename & delete using file system Module in
NodeJS
Execute the concept of URL Module . Run a
04 program to split a web address into readable
parts using url.parse() method
Implement NodeJS event module . Run a
05
NodeJS program using EventEmitter class
Explore the database MongoDB & setup its
environment for development. Create a
06 MongoDB document using fields numbers,
strings, boolean, arrays, or even nested
documents.
Develop a database & collection using NodeJS &
07
MongoDB.
Apply Insert operation in MongoDB to insert a
08 document into collection & run a program into
NodeJS.
Implement delete operation in MongoDB to
09 delete a record from collection & run a program
in NodeJS.
Compile a NodeJS program to update the
10 record in collection in MongoDB using
UpdateOne() command.

Computer Science and Engineering Department


Programming skill Lab II (CS410)

PRACTICAL NO. 1

AIM: Explore the concept of NodeJS & Setup its environment for development.
Run a Node Js program to print ‘Hello world’

OBJECTIVES: (a) To introduce Node.js


(b) To setup Node.js environment and print hello world.

SOFTWARE: Node JS, Command Prompt

THEORY:

Introduction to Node.js-
Node.js is a cross-platform environment and library for running JavaScript
applications which is used to create networking and server-side applications.
It is used for creating server-side and networking web applications. It is open
source and free to use. It can be downloaded from this link https://nodejs.org/en/
Node.js is mostly used to run real-time server applications.

1.What can Node.js do?


 Node.js can generate dynamic page content.
 Node.js can create, open, read, write, delete and close the files on server.
 Node.js is a platform built on Chrome's JavaScript runtime for easily
building fast and scalable network applications.
 Node.js uses an event-driven, non-blocking I/O model that makes it
lightweight and efficient, perfect for data-intensive real-time applications
that run across distributed devices.
 Node.js also provides a rich library of various JavaScript modules to
simplify the development of web applications.
What is Node.js file?

 Node.js files contain the task that will be executed on certain event.
 A typical event is someone trying to access to a part of server.
 Node.js files must be initiated on the server before having any effect.
 Node.js files have extension “ .js”
Node.js uses asynchronous programming. A common task for a web server can
be to open a files on the server & return the content to the client.

Lets see how PHP or ASP handles the file request.


 Send the task to the computer’s file system.
 Waits while the file system opens and read the file.
 Returns the contents to the client
 Ready to handle the next request.
Lets see how the Node.js handle the file request.
 Send the task to the computer file system .
 Ready to handle the next request

Computer Science and Engineering Department


Programming skill Lab II (CS410)

 When the file system has opened and read the file , the server returns
the content to the file .
 Node.js eliminates the waiting and simply continues with the next
request.
 Node.js runs single threaded , non-blocking asynchronous programing
which is very memory efficient .
Installation
Download Node.js from official Node.js website .https://nodejs.org

To install and setup an environment for Node.js, you need the following two
software’s available on your computer:

1. Text Editor.
2. Node.js Binary installable
3. Text Editor:
4. 1.The text editor is used to type your program. For example: Notepad is
used in Windows, vim or vi can be used on Windows as well as Linux or
UNIX. The name and version of the text editor can be different from
operating system to operating system.
5. 2.The files created with text editor are called source files and contain
program source code. The source files for Node.js programs are typically
named with the extension ".js".

The Node.js Runtime:

The source code written in source file is simply JavaScript. It is interpreted and
executed by the Node.js interpreter.

How to download Node.js:

You can download the latest version of Node.js installable archive file
from https://nodejs.org/en/

Here, you deploy the installation of node-v4.4.2 LTS recommended for most
users.

Computer Science and Engineering Department


Programming skill Lab II (CS410)

Accept the terms of license agreement.

Choose the location where you want to install.

Computer Science and Engineering Department


Programming skill Lab II (CS410)

Ready to install:

Computer Science and Engineering Department


Programming skill Lab II (CS410)

CONCLUSION:

ASSESSMENT SCHEME:

Process Related Product Related Total Signature of


Skills Skills (25-M) Faculty
(15-M) (10-M)

Computer Science and Engineering Department


Programming skill Lab II (CS410)

PRACTICAL NO. 2
AIM: Accomplish the concept of HTTP module & Run a program in NodeJS.

OBJECTIVES: (a) To understand http module


(b) To create a simple web server using node.js

SOFTWARE: Node Js, Command Prompt

THEORY: What is module in Node.js? Modules to be the same as Javascript


libraries . A set of function you want to include in your application.

Built-In modules
Node.js has set of built in modules which you can use without any further
installation.

Modules Description
Assert Provides a set of assertion task
Buffer To handle the binary data
Child-process To run a child process
Cluster To split a single node process into multiple processes.
Crypto To handle open SSL cryptographic function
Dgram Provides implementation of UDP diagram socket
Dns To do DNS lookups and name resolution functions
Domain Deprecated. To handle unhandled errors.
Events To handle the events
Fs To handle the file system
http To make node.js act as a http server
https To make node.js act as a https server
Net To create the servers & clients
Os Provide info about the operation system
Path To handle the file paths
Punycode Deprecated. A character encoding scheme.
Query string To handle URL query string
Readline To handle readable strings one at a time.
Stream To handle the streaming data
String decoder To decode buffer objects into strings
Timers To execute the function after the given number of ms
Tls To implement TLS & SSL protocol
Tty Provides classes use by text terminal
url To parse url string
Util To access the utility functions
V8 To access the information about javascript engine(v8)
Vm To compile javascript code into the virtual machine
Zlib To compress or decompress the file

Node.js has a built-in module called HTTP, which allows Node.js to transfer data
over the Hypertext Transfer Protocol (HTTP). The HTTP module can create an

Computer Science and Engineering Department


Programming skill Lab II (CS410)

HTTP server that listens to server ports and gives a response back to the client.

There are variety of modules such as “http” & “request” module which helps in
processing the server related requests in the web server space.
We will have a look how we can create a basic web server application using
Node.js

To implement web server in Node.js

Program Input:

Program Output:

CONCLUSION:

ASSESSMENT SCHEME:

Process Related Product Related Total Signature of


Skills Skills (25-M) Faculty
(15-M) (10-M)

Computer Science and Engineering Department


Programming skill Lab II (CS410)

PRACTICAL NO. 3

AIM: To study and implement Node.js File system module to read, write, create,
update, delete and rename the file.

OBJECTIVES: (a) To understand the file system module.


(b) To implement the file system module.

SOFTWARE: Node Js, Command Prompt

THEORY: The Node.js file system module allows you to work with the file
system on your computer. To include the file system module , use the require()
method.
Var fs=require(‘fs’);
Common use for the file system module:
 Read files
 Create files
 Update files
 Delete files
 Rename files

Program code:

Program Output:

CONCLUSION:

ASSESSMENT SCHEME:

Process Related Product Related Total Signature of


Skills Skills (25-M) Faculty
(15-M) (10-M)

Computer Science and Engineering Department


Programming skill Lab II (CS410)

PRACTICAL NO. 4

AIM: Execute the concept of URL Module . Run a program to split a web address
into readable parts using url.parse() method

OBJECTIVES: (a) To understand the URL module of the Node.js


(b)To write a program to open a requested file & returns the
contents of
file to client.

SOFTWARE: Node Js, Command Prompt

THEORY: The URL module splits up a web address into readable parts.

To include the URL module, use the require() method:

Program Input:

Program Output:

CONCLUSION:

ASSESSMENT SCHEME:

Process Related Product Related Total Signature of


Skills Skills (25-M) Faculty
(15-M) (10-M)

Computer Science and Engineering Department


Programming skill Lab II (CS410)

PRACTICAL NO. 5

AIM: Implement NodeJS event module . Run a NodeJS program using


EventEmitter class.

OBJECTIVES:
(a) To study event handling in Node JS and demonstrate it using Event Module
and Event Emitter Object
(b) To demonstrate using event module & event emitter object

SOFTWARE: Node JS

THEORY : Every action on a computer is an event. Like when a connection is


made or a file is opened.

Objects in Node.js can fire events, like the readStream object fires events when
opening and closing a file:

Example,

var fs = require('fs');
var rs = fs.createReadStream('./demofile.txt');
rs.on('open', function () {
console.log('The file is open');
});

What is Event Module in Node JS?

Node.js has a built-in module, called "Events", where you can create, fire, and
listen for- your own events.To include the built-in Events module use
the require() method. In addition, all event properties and methods are an
instance of an EventEmitter object. To be able to access these properties and
methods, create an EventEmitter object:

Syntax : var events = require('events');


var eventEmitter = new events.EventEmitter();

What is EventEmitter Object in Node JS ?


You can assign event handlers to your own events with the EventEmitter object.
In the example below we have created a function that will be executed when a ""
event is fired.
To fire an event, use the emit() method.

Computer Science and Engineering Department


Programming skill Lab II (CS410)

Program code:

Program Output:

CONCLUSION:

ASSESSMENT SCHEME:

Process Related Product Related Total Signature of


Skills Skills (25-M) Faculty
(15-M) (10-M)

Computer Science and Engineering Department


Programming skill Lab II (CS410)

PRACTICAL NO. 6

AIM: Explore the database MongoDB & setup its environment for development.
Create a MongoDB document using fields numbers, strings, boolean, arrays, or
even nested documents.

OBJECTIVES: (a) To set up and configure the MongoDB development


environment.
(b) To understand the basic structure and working of
MongoDB.
(c) To establish a connection with MongoDB using the shell
and Node.js.

SOFTWARE: MongoDB Community Edition, MongoDB Shell (mongosh), Node.js

THEORY:

Introduction to MongoDB: MongoDB is a document-oriented NoSQL database


that stores data in flexible, JSON-like documents called BSON (Binary JSON).
Unlike traditional relational databases that use tables and rows, MongoDB uses
collections and documents, providing a more dynamic and scalable approach to
data storage.

JSON (JavaScript Object Notation) is a lightweight data format used for storing
and exchanging data in a human-readable format. It represents data as key-
value pairs enclosed in curly braces {} and supports various data types like
strings, numbers, arrays, and objects. MongoDB uses BSON (Binary JSON), an
extended version of JSON, for efficient storage and retrieval. Due to its simplicity
and flexibility, JSON is widely used in NoSQL databases, APIs, and web
applications.

Key Features of MongoDB:

 Schema-less: Documents can have varying structures, allowing flexibility


in data modeling.
 Scalability: Designed to scale out horizontally through sharding.
 High Performance: Optimized for read and write operations.
 Rich Query Language: Supports a powerful query language for data
retrieval and manipulation.

Setting Up the Development Environment:

1. Install MongoDB:

Computer Science and Engineering Department


Programming skill Lab II (CS410)

o Download the appropriate version of MongoDB for your operating


system from the official MongoDB website
https://www.mongodb.com/try/download/community.
o Follow the installation instructions provided to set up MongoDB on
your system.
o After downloading MongoDB you need to download MongoDB Shell
2. Install MongoDB Shell (mongosh):

After downloading it Extract the folder and navigate to all folder inside it
till Bin occurs. Go inside Bin and copy the path of this location.

Computer Science and Engineering Department


Programming skill Lab II (CS410)

After copying this path we need to add the Environment variable to the
system. Search in search bar “Add environment variable”

Computer Science and Engineering Department


Programming skill Lab II (CS410)

Click on Environment Variable, Select the “Path” in system variables list


and then click “edit”

After clicking edit new window will open, click on “New” button and paste
copied path to last blank space then hit “OK”

Hit OK again two times in order to save changes.

Computer Science and Engineering Department


Programming skill Lab II (CS410)

Computer Science and Engineering Department


Programming skill Lab II (CS410)

Now go to command prompt and write command “mongosh”

You will see current mongosh login ID and other information

3. Install MongoDB Node.js Driver:

 Open your terminal or command prompt.


 Navigate to your project directory.
 Run the following command to install the MongoDB driver:

npm install mongodb

Input Program Code:

Output:

Computer Science and Engineering Department


Programming skill Lab II (CS410)

CONCLUSION: .

ASSESSMENT SCHEME:

Process Related Product Related Total Signature of


Skills Skills (25-M) Faculty
(15-M) (10-M)

PRACTICAL NO. 7

Computer Science and Engineering Department


Programming skill Lab II (CS410)

AIM: Develop a database & collection using NodeJS & MongoDB.(Create).

OBJECTIVEs: (a) To set up a MongoDB database using Node.js.


(b) To create and manage collections in MongoDB.

SOFTWARE: MongoDB Community Edition, MongoDB Shell (mongosh), Node.js

THEORY: MongoDB does not require manually creating a database before use. A
database is created automatically when data is first inserted. Similarly,
collections, which store documents, are automatically created when data is
added. Collections in MongoDB are equivalent to tables in relational databases
but are more flexible, as they do not enforce a fixed schema. Each collection can
contain multiple documents with different structures. MongoDB uses BSON
(Binary JSON) format to store data efficiently. Unlike traditional SQL databases,
MongoDB is designed for scalability, high performance, and easy handling of
unstructured data.
MongoDB provides commands in mongosh to check, create, and manage
databases and collections.

Steps to Create a Database and Collection

1. Open MongoDB Shell (mongosh).


o The MongoDB shell (mongosh) is an interactive JavaScript-based
interface used to communicate with MongoDB.
o Run the following command in the terminal or command prompt:

mongosh

2. Create or Switch to a Database.


o MongoDB does not require an explicit database creation command.
Instead, the use command switches to the specified database. If the
database does not exist, it is created when data is inserted.
o Command:

use myDatabase

3. Verify the Database.


o The db command displays the current active database. If the
database was recently created but contains no collections, it will not
appear in the list of databases.
o Commands:
1. db # Shows the current database
2. show dbs # Lists all databases
4. Create a Collection.
o Collections in MongoDB are equivalent to tables in relational
databases. A collection is automatically created when the first
document is inserted, but can also be manually created using
createCollection.

Computer Science and Engineering Department


Programming skill Lab II (CS410)

o Command:

db.createCollection("students")

5. Verify the Collection.


o The show collections command lists all collections in the active
database. If no collection has been created, this command will
return an empty result.
o Command:

show collections

6. Exit the MongoDB Shell.


o To exit mongosh and return to the terminal or command prompt,
use the exit command.
o Command:

exit

Input Program Code:

Output:

CONCLUSION: and efficient for handling unstructured data.

ASSESSMENT SCHEME:

Process Related Product Related Total Signature of


Skills Skills (25-M) Faculty
(15-M) (10-M)

Computer Science and Engineering Department


Programming skill Lab II (CS410)

PRACTICAL NO. 8

AIM: Apply Insert operation in MongoDB to insert a document into collection &
run a program into NodeJS.

OBJECTIVES (a) To apply insert operations in MongoDB.


(b) To retrieve inserted documents using the find command.

SOFTWARE: MongoDB Community Edition, MongoDB Shell ( mongosh)

THEORY:

MongoDB stores data in the form of JSON-like documents inside collections. The
insertOne method is used to insert a single document, while insertMany allows
multiple documents to be added at once. The find command helps in retrieving
stored documents from a collection. MongoDB dynamically creates collections
when the first document is inserted. Unlike SQL databases, there is no need to
define a schema before inserting data.

Steps to Insert Documents in MongoDB

1. Open MongoDB Shell (mongosh).


o Start mongosh to interact with MongoDB.
o Command: mongosh
2. Switch to a Database.
o Use the use command to select the database where the collection
exists.
o Command: use myDatabase
3. Insert a Single Document.
o The insertOne method adds a single document to a collection.
o Command:

db.students.insertOne({ name: "John", age: 22, course: "IT" })

4. Insert Multiple Documents.


o The insertMany method inserts multiple documents at once.
o Command:
o db.students.insertMany([
o { name: "Alice", age: 21, course: "CS" },
o { name: "Bob", age: 23, course: "ECE" }
])

5. Retrieve Inserted Documents.


o The find command fetches all documents from the collection.
o Command: db.students.find()
6. Exit the MongoDB Shell.

Computer Science and Engineering Department


Programming skill Lab II (CS410)

o Command: exit

Input Program Code:

Output:

CONCLUSION:

ASSESSMENT SCHEME:

Process Related Product Related Total Signature of


Skills Skills (25-M) Faculty
(15-M) (10-M)

Computer Science and Engineering Department


Programming skill Lab II (CS410)

PRACTICAL NO. 9

AIM: Implement delete operation in MongoDB to delete a record from collection


& run a program in NodeJS.
OBJECTIVES: (a) To delete documents from a collection.
(b) To drop a collection from a database.

SOFTWARE: MongoDB Community Edition, MongoDB Shell ( mongosh)

THEORY:
MongoDB provides methods to remove data. The deleteOne method removes a
single document that matches the given criteria, while deleteMany removes
multiple matching documents. The drop method is used to delete an entire
collection, including its indexes.
MongoDB stores data in the form of JSON-like documents inside collections. The
insertOne method is used to insert a single document, while insertMany allows
multiple documents to be added at once. The find command helps in retrieving
stored documents from a collection. MongoDB dynamically creates collections
when the first document is inserted. Unlike SQL databases, there is no need to
define a schema before inserting data.

Steps to Insert Documents in MongoDB


1. Open MongoDB Shell (mongosh).
o mongosh is used to interact with MongoDB via the command line.
o Command: mongosh
2. Switch to a Database.
o The use command selects the database where the collection exists
or creates a new one if it doesn't exist.
o Command: use myDatabase
3. Insert a Single Document.
o The insertOne method adds a single document to a collection.
o Command:
db.students.insertOne({ name: "John", age: 22, course: "IT" })
4. Insert Multiple Documents.
o The insertMany method inserts multiple documents at once.
o Command:
db.students.insertMany( [
{ name: "Alice", age: 21, course: "CS" },
{ name: "Bob", age: 23, course: "ECE" }
])
5. Retrieve Inserted Documents.

Computer Science and Engineering Department


Programming skill Lab II (CS410)

o The find command fetches all documents from the collection.


o Command: db.students.find()
6. Exit the MongoDB Shell.
o Use the exit command to leave the shell.
o Command: exit

Input Program Code:

Output:

CONCLUSION:

ASSESSMENT SCHEME:

Process Related Product Related Total Signature of


Skills Skills (25-M) Faculty
(15-M) (10-M)

Computer Science and Engineering Department


Programming skill Lab II (CS410)

PRACTICAL NO. 10

AIM: Compile a NodeJS program to update the record in collection in MongoDB


using UpdateOne() command.
OBJECTIVES: To modify existing documents using update operations.

SOFTWARE: MongoDB Community Edition, MongoDB Shell ( mongosh)

THEORY:

MongoDB provides updateOne and updateMany to modify existing documents.


The $set operator updates specific fields without altering others. The $inc
operator can be used to increment numeric fields, while $rename renames fields
in a document.

In MongoDB, $ is a special operator used in various contexts, such as updating


and querying documents. It acts as a placeholder for matching array elements in
update operations. The $set operator updates specific fields, $inc increments
numeric values, and $push adds elements to an array. Additionally, $ can be
used as a positional operator to modify the first matching array element. These
operators provide flexibility for dynamic data manipulation.

Steps to Perform Update Operations

1. Open MongoDB Shell (mongosh).


o This starts the shell for executing MongoDB commands.
2. Select a Database.
o The use command ensures updates are performed in the correct
database.

use myDatabase

3. Update a Single Document.


o The updateOne method modifies the first document that matches
the filter criteria.

db.students.updateOne({ name: "Alice" }, { $set: { age: 25 } })

4. Update Multiple Documents.


o The updateMany method applies changes to all matching
documents.

Computer Science and Engineering Department


Programming skill Lab II (CS410)

db.students.updateMany({}, { $set: { course: "Updated


Course" } })

Input Program Code:

Output:

CONCLUSION:

ASSESSMENT SCHEME:
Process Related Product Related Total Signature of
Skills Skills (25-M) Faculty
(15-M) (10-M)

Computer Science and Engineering Department

You might also like