SlideShare a Scribd company logo
Connect to NoSQL Database
using Node JS
Dr.T.Abirami
Associate Professor
Department of IT
Kongu Engineering College
Dr.T.Abirami / Associate Professor / Department of IT/ KEC
What Is a Database
• A database is an organized collection of structured
information, or data, typically stored electronically in
a computer system
Dr.T.Abirami / Associate Professor / Department of IT/ KEC
Types of databases
• Centralised database.
• Distributed database.
• Personal database.
• End-user database.
• Commercial database.
• NoSQL database.
• Operational database.
• Relational database.
• Cloud database.
• Object-oriented database.
• Graph database.
Dr.T.Abirami / Associate Professor / Department of IT/ KEC
1. Centralised Database
• The information(data) is stored at a centralized location and
the users from different locations can access this data.
• This type of database contains application procedures that
help the users to access the data even from a remote
location.
Dr.T.Abirami / Associate Professor / Department of IT/ KEC
Distributed Database
• Just opposite of the centralized database concept,
• The data is not at one place and is distributed at various
sites of an organization. These sites are connected to
each other with the help of communication links which
helps them to access the distributed data easily.
Dr.T.Abirami / Associate Professor / Department of IT/ KEC
Introduction to NoSQL
•NoSQL is a type of database management
system (DBMS) that is designed to handle and
store large volumes of unstructured and semi-
structured data.
•NoSQL originally referred to “non-SQL” or “non-
relational” databases
Dr.T.Abirami / Associate Professor / Department of IT/ KEC
NoSQL Database
•It is used for large sets of distributed data.
•There are some big data performance issues which are
effectively handled by relational databases, such kind of
issues are easily managed by NoSQL databases.
•There are very efficient in analyzing large size unstructured
data that may be stored at multiple virtual servers of the
cloud.
Dr.T.Abirami / Associate Professor / Department of IT/ KEC
Cloud and Database
• A cloud is a network of remote servers that are connected to the
internet, and are used to store, manage and process data.
• Cloud services can be divided into three categories:
• Infrastructure as a Service (IaaS),
• Platform as a Service (PaaS) and
• Software as a Service (SaaS). T
• he main benefit of cloud computing is its scalability, as well as its
ability to provide on-demand access to computing resources and
services.
Dr.T.Abirami / Associate Professor / Department of IT/ KEC
Cloud and Database
• A database is a collection of data that is organized in a specific way
and can be accessed, managed and updated by a software
application.
• Databases are used to store and retrieve data in an efficient and
organized manner.
• There are different types of databases, such as
• relational databases (MySQL, Oracle, MS SQL), NoSQL databases
(MongoDB, Cassandra, Redis) and graph databases (Neo4j).
Dr.T.Abirami / Associate Professor / Department of IT/ KEC
Cloud and Database
• cloud is a type of technology that provides access to
remote servers and computing resources
• database is a collection of data that is organized and
managed by a specific software.
• While they are different, they can be used together,
such as running a database in a cloud environment.
Dr.T.Abirami / Associate Professor / Department of IT/ KEC
Dr.T.Abirami / Associate Professor / Department of IT/ KEC
JSON / JavaScript Object Notation Basics
• It is a text-based data exchange format.
• It is a collection of key-value pairs
• where the key must be a string type, and the value can be of any of the
following types:
• Number
• String
• Boolean
• Array
• Object
• null
Dr.T.Abirami / Associate Professor / Department of IT/ KEC
Simple JSON Data
{
"name": "Alex C",
"age": 22,
"city": “Erode"
}
Dr.T.Abirami / Associate Professor / Department of IT/ KEC
[
{
"name": "Alex C",
"age": 24,
"city": “Erode"
},
{
"name": "John G",
"age": 40,
"city": "Washington"
},
{
"name": "Bala T",
"age": 22,
"city": "Bangalore"
}
]
JSON Data with a
Collection of Ordered
Records
Dr.T.Abirami / Associate Professor / Department of IT/ KEC
Employee Data in
JSON Format
{
"name": "Aleix Melon",
"id": "E00245",
"role": ["Dev", "DBA"],
"age": 23,
"doj": "11-12-2019",
"married": false,
"address": {
"street": "32, Laham St.",
"city": "Innsbruck",
"country": "Austria"
},
"referred-by": "E0012"
}
Dr.T.Abirami / Associate Professor / Department of IT/ KEC
[ { "name": "Aleix Melon",
"id": "E00245",
"role": ["Dev", "DBA"],
"age": 23,
"doj": "11-12-2019",
"married": false,
"address": { "street": "32, Laham St.",
"city": "Innsbruck",
"country": "Austria"
}, "referred-by": "E0012"
},
{ "name": "Bob Washington",
"id": "E01245",
"role": ["HR"], "age": 43,
"doj": "10-06-2010", "married": true,
"address": { "street": "45, Abraham Lane.",
"city": "Washington", "country": "USA"
}, "referred-by": null } ]
An Array of Employee
Data in JSON Format
Dr.T.Abirami / Associate Professor / Department of IT/ KEC
File: first.json
{"employees":[
{"name":"Sonoo", "email":"sonoojaiswal1987@gmail.com"},
{"name":"Rahul", "email":"rahul32@gmail.com"},
{"name":"John", "email":"john32bob@gmail.com"}
]}
Dr.T.Abirami / Associate Professor / Department of IT/ KEC
MongoDB
• MongoDB is a NoSQL database.
• MongoDB is an open source, document oriented database
that stores data in form of documents (key and value pairs).
Dr.T.Abirami / Associate Professor / Department of IT/ KEC
Fields (key and value pairs) are stored in document, documents are
stored in collection and collections are stored in database.
Dr.T.Abirami / Associate Professor / Department of IT/ KEC
Dr.T.Abirami / Associate Professor / Department of IT/ KEC
CRUD operations in MongoDB
• Create: This operation allows you to insert new documents into a
MongoDB collection. A document is a data structure that consists of field-
value pairs, similar to a JSON object.
• Read: This operation allows you to retrieve data from a MongoDB
collection. You can retrieve a single document or multiple documents that
match a specific query.
• Update: This operation allows you to modify existing documents in a
MongoDB collection. You can update one or multiple documents that
match a specific query.
• Delete: This operation allows you to remove documents from a MongoDB
collection. You can delete a single document or multiple documents that
match a specific query.
Dr.T.Abirami / Associate Professor / Department of IT/ KEC
Download MongoDB
• download MongoDB from the official website:
https://www.mongodb.com/download-
center/community.
• MongoDB driver for our programming language.
• using the official MongoDB driver for Node.js.
• You can install it by running the following command:
npm install mongodb
npm install mongoose
Dr.T.Abirami / Associate Professor / Department of IT/ KEC
Dr.T.Abirami / Associate Professor / Department of IT/ KEC
Dr.T.Abirami / Associate Professor / Department of IT/ KEC
Dr.T.Abirami / Associate Professor / Department of IT/ KEC
Dr.T.Abirami / Associate Professor / Department of IT/ KEC
Step 1 : Check properly installed or not
Open cmd and type:
• mongod -version
• mongo -version
Dr.T.Abirami / Associate Professor / Department of IT/ KEC
Step 2 : Server on & Client on
Open two separate cmd and type: One for server & another for
client
• mongod
• mongo
Dr.T.Abirami / Associate Professor / Department of IT/ KEC
Within Mongo (Client) window
Shows databases
show dbs
Ans:
admin 0.000GB
config 0.000GB
local 0.000GB
Dr.T.Abirami / Associate Professor / Department of IT/ KEC
Create database
use Employee
Ans:
switched to db Employee
Dr.T.Abirami / Associate Professor / Department of IT/ KEC
Create collection /table
db.createCollection("posts")
Ans:
{ "ok" : 1 }
Dr.T.Abirami / Associate Professor / Department of IT/ KEC
Insert data
db.posts.insertOne({name:"abi"})
Ans:
{
"acknowledged" : true,
"insertedId" :
ObjectId("643e391ee1f9ddc511f3beaf")
}
Dr.T.Abirami / Associate Professor / Department of IT/ KEC
View / Select /find a data
db.posts.find()
Ans:
{ "_id" : ObjectId("643e391ee1f9ddc511f3beaf"),
"name" : "abi" }
Dr.T.Abirami / Associate Professor / Department of IT/ KEC
Update command
db.posts.update({name:"abi"},{$set:{name:"helloword"}})
Ans:
WriteResult({ "nMatched" : 1, "nUpserted" : 0, "nModified" : 1
})
Dr.T.Abirami / Associate Professor / Department of IT/ KEC
Delete command
db.posts.deleteOne({ name: "helloword" })
Ans:
{ "acknowledged" : true, "deletedCount" : 1 }
Dr.T.Abirami / Associate Professor / Department of IT/ KEC
MongoDB – sort() Method
• The sort() method specifies the order in which the query returns the
matching documents from the given collection.
db.Collection_Name.sort({filed_name:1 or -1})
db.student.find().sort({age:1})
• Parameter:
The value is 1 or -1 that specifies an ascending or descending
sort respectively. The type of parameter is a document.
Dr.T.Abirami / Associate Professor / Department of IT/ KEC
Connect Node.js with NoSQL MongoDB
Database
Install mongoose:
• Step 1: install the mongoose module. You can install this package by using
this command.
npm install mongoose
• Step 2: Now you can import the mongoose module in your file using:
const mongoose = require('mongoose');
Dr.T.Abirami / Associate Professor / Department of IT/ KEC
Mongoose Module Introduction
•It provides several functions in order to
manipulate the documents of the collection of
the MongoDB database
Dr.T.Abirami / Associate Professor / Department of IT/ KEC
Mongoose
• Mongoose is an Object Data Modeling (ODM) tool designed
to work in an asynchronous environment.
• Mongoose schema as a blueprint for defining the structure
of a Mongoose model that maps directly to a MongoDB
collection.
Dr.T.Abirami / Associate Professor / Department of IT/ KEC
• -->unifiedtopology : DeprecationWarning: current Server Discovery and
Monitoring engine is deprecated, and will be removed in a future version.
• To use the new Server Discover and Monitoring engine, pass option {
useUnifiedTopology: true } to the MongoClient constructor.
• -->usenewurlparser : DeprecationWarning: current URL string parser is
deprecated, and will be removed in a future version. To use the new parser,
pass option { useNewUrlParser: true } to MongoClient.connect.
Dr.T.Abirami / Associate Professor / Department of IT/ KEC
Step 1 : create schema and set model
const mongoose =require("mongoose")
const url = "mongodb://localhost:27017/project";
const name = new mongoose.Schema({ name: String,
age:Number, rollno:String });
const Name= mongoose.model('Name',name)
Dr.T.Abirami / Associate Professor / Department of IT/ KEC
const db = async() =>{
try{
console.log("entered")
const data=await mongoose.connect(url,
{
useNewUrlParser: true,
useUnifiedTopology: true,
family: 4,
}
)
console.log("connected")
}
catch(err){
console.log(err)
}
}
db()
Step 2 : create
connection
Dr.T.Abirami / Associate Professor / Department of IT/ KEC
Insert data
const insertdata=async()=>{
const cat = new Name({ name: 'Zildjian' , age:25, rollno:"21ITR089"});
cat.save().then(() => console.log('Saved in db'));
}
Insertdata()
Dr.T.Abirami / Associate Professor / Department of IT/ KEC
Update query
const updatedata=async() => {
const filter = { name: "Zildjian" };
const update = { age: 97 };
let doc = await Name.findOneAndUpdate(filter, update);
console.log(doc.name); // 'Luke Skywalker'
console.log(doc.age); // undefined
}
updatedata()
Dr.T.Abirami / Associate Professor / Department of IT/ KEC
Delete query
const deletedata=async() => {
await Name.deleteMany({name: 'Zildjian'});
}
deletedata()
Dr.T.Abirami / Associate Professor / Department of IT/ KEC
Reference
• https://masteringjs.io/mongoose
• https://www.mongodb.com/docs/manual/tutorial/install-mongodb-
on-windows/
• https://mongoosejs.com/docs/5.x/docs/tutorials/findoneandupdate.
html
Dr.T.Abirami / Associate Professor / Department of IT/ KEC

More Related Content

Similar to Connect to NoSQL Database using Node JS.pptx

Database@Home - Data Driven : Loading, Indexing, and Searching with Text and ...
Database@Home - Data Driven : Loading, Indexing, and Searching with Text and ...Database@Home - Data Driven : Loading, Indexing, and Searching with Text and ...
Database@Home - Data Driven : Loading, Indexing, and Searching with Text and ...
Tammy Bednar
 
Database system
Database system Database system
Database system
Hitesh Mohapatra
 
Adv DB - Full Handout.pdf
Adv DB - Full Handout.pdfAdv DB - Full Handout.pdf
Adv DB - Full Handout.pdf
3BRBoruMedia
 
Normalisation in Database management System (DBMS)
Normalisation in Database management System (DBMS)Normalisation in Database management System (DBMS)
Normalisation in Database management System (DBMS)
Prof Ansari
 
RDMS AND SQL
RDMS AND SQLRDMS AND SQL
RDMS AND SQL
milanmehta7
 
Module 1 - Chapter1.pptx
Module 1 - Chapter1.pptxModule 1 - Chapter1.pptx
Module 1 - Chapter1.pptx
SoniaDevi15
 
Info systems databases
Info systems databasesInfo systems databases
Info systems databases
MR Z
 
Microsoft Azure Big Data Analytics
Microsoft Azure Big Data AnalyticsMicrosoft Azure Big Data Analytics
Microsoft Azure Big Data Analytics
Mark Kromer
 
ГАННА КАПЛУН «noSQL vs SQL: порівняння використання реляційних та нереляційни...
ГАННА КАПЛУН «noSQL vs SQL: порівняння використання реляційних та нереляційни...ГАННА КАПЛУН «noSQL vs SQL: порівняння використання реляційних та нереляційни...
ГАННА КАПЛУН «noSQL vs SQL: порівняння використання реляційних та нереляційни...
QADay
 
Using Document Databases with TYPO3 Flow
Using Document Databases with TYPO3 FlowUsing Document Databases with TYPO3 Flow
Using Document Databases with TYPO3 Flow
Karsten Dambekalns
 
Introduction to oop
Introduction to oop Introduction to oop
Introduction to oop Kumar
 
Enabling Fine-grained Multi-keyword Search Supporting Classified Sub-dictiona...
Enabling Fine-grained Multi-keyword Search Supporting Classified Sub-dictiona...Enabling Fine-grained Multi-keyword Search Supporting Classified Sub-dictiona...
Enabling Fine-grained Multi-keyword Search Supporting Classified Sub-dictiona...
1crore projects
 
Enabling Fine-grained Multi-keyword Search Supporting Classified Sub-dictiona...
Enabling Fine-grained Multi-keyword Search Supporting Classified Sub-dictiona...Enabling Fine-grained Multi-keyword Search Supporting Classified Sub-dictiona...
Enabling Fine-grained Multi-keyword Search Supporting Classified Sub-dictiona...
1crore projects
 
oodb.ppt
oodb.pptoodb.ppt
oodb.ppt
ISHAAGARWAL75
 
NoSQL and Spatial Database Capabilities using PostgreSQL
NoSQL and Spatial Database Capabilities using PostgreSQLNoSQL and Spatial Database Capabilities using PostgreSQL
NoSQL and Spatial Database Capabilities using PostgreSQL
EDB
 
Database Management System
Database Management SystemDatabase Management System
Database Management System
NILESH UCHCHASARE
 
Elastic search and Symfony3 - A practical approach
Elastic search and Symfony3 - A practical approachElastic search and Symfony3 - A practical approach
Elastic search and Symfony3 - A practical approach
SymfonyMu
 
DBMS architecture &; system structure
DBMS architecture &; system  structureDBMS architecture &; system  structure
DBMS architecture &; system structure
RUpaliLohar
 
The Fine Art of Schema Design in MongoDB: Dos and Don'ts
The Fine Art of Schema Design in MongoDB: Dos and Don'tsThe Fine Art of Schema Design in MongoDB: Dos and Don'ts
The Fine Art of Schema Design in MongoDB: Dos and Don'ts
Matias Cascallares
 

Similar to Connect to NoSQL Database using Node JS.pptx (20)

Database@Home - Data Driven : Loading, Indexing, and Searching with Text and ...
Database@Home - Data Driven : Loading, Indexing, and Searching with Text and ...Database@Home - Data Driven : Loading, Indexing, and Searching with Text and ...
Database@Home - Data Driven : Loading, Indexing, and Searching with Text and ...
 
Database system
Database system Database system
Database system
 
Adv DB - Full Handout.pdf
Adv DB - Full Handout.pdfAdv DB - Full Handout.pdf
Adv DB - Full Handout.pdf
 
Normalisation in Database management System (DBMS)
Normalisation in Database management System (DBMS)Normalisation in Database management System (DBMS)
Normalisation in Database management System (DBMS)
 
RDMS AND SQL
RDMS AND SQLRDMS AND SQL
RDMS AND SQL
 
Module 1 - Chapter1.pptx
Module 1 - Chapter1.pptxModule 1 - Chapter1.pptx
Module 1 - Chapter1.pptx
 
Info systems databases
Info systems databasesInfo systems databases
Info systems databases
 
Microsoft Azure Big Data Analytics
Microsoft Azure Big Data AnalyticsMicrosoft Azure Big Data Analytics
Microsoft Azure Big Data Analytics
 
ГАННА КАПЛУН «noSQL vs SQL: порівняння використання реляційних та нереляційни...
ГАННА КАПЛУН «noSQL vs SQL: порівняння використання реляційних та нереляційни...ГАННА КАПЛУН «noSQL vs SQL: порівняння використання реляційних та нереляційни...
ГАННА КАПЛУН «noSQL vs SQL: порівняння використання реляційних та нереляційни...
 
Using Document Databases with TYPO3 Flow
Using Document Databases with TYPO3 FlowUsing Document Databases with TYPO3 Flow
Using Document Databases with TYPO3 Flow
 
Introduction to oop
Introduction to oop Introduction to oop
Introduction to oop
 
My sql
My sqlMy sql
My sql
 
Enabling Fine-grained Multi-keyword Search Supporting Classified Sub-dictiona...
Enabling Fine-grained Multi-keyword Search Supporting Classified Sub-dictiona...Enabling Fine-grained Multi-keyword Search Supporting Classified Sub-dictiona...
Enabling Fine-grained Multi-keyword Search Supporting Classified Sub-dictiona...
 
Enabling Fine-grained Multi-keyword Search Supporting Classified Sub-dictiona...
Enabling Fine-grained Multi-keyword Search Supporting Classified Sub-dictiona...Enabling Fine-grained Multi-keyword Search Supporting Classified Sub-dictiona...
Enabling Fine-grained Multi-keyword Search Supporting Classified Sub-dictiona...
 
oodb.ppt
oodb.pptoodb.ppt
oodb.ppt
 
NoSQL and Spatial Database Capabilities using PostgreSQL
NoSQL and Spatial Database Capabilities using PostgreSQLNoSQL and Spatial Database Capabilities using PostgreSQL
NoSQL and Spatial Database Capabilities using PostgreSQL
 
Database Management System
Database Management SystemDatabase Management System
Database Management System
 
Elastic search and Symfony3 - A practical approach
Elastic search and Symfony3 - A practical approachElastic search and Symfony3 - A practical approach
Elastic search and Symfony3 - A practical approach
 
DBMS architecture &; system structure
DBMS architecture &; system  structureDBMS architecture &; system  structure
DBMS architecture &; system structure
 
The Fine Art of Schema Design in MongoDB: Dos and Don'ts
The Fine Art of Schema Design in MongoDB: Dos and Don'tsThe Fine Art of Schema Design in MongoDB: Dos and Don'ts
The Fine Art of Schema Design in MongoDB: Dos and Don'ts
 

More from Kongu Engineering College, Perundurai, Erode

Introduction to Spring & Spring BootFramework
Introduction to Spring  & Spring BootFrameworkIntroduction to Spring  & Spring BootFramework
Introduction to Spring & Spring BootFramework
Kongu Engineering College, Perundurai, Erode
 
A REST API (also called a RESTful API or RESTful web API) is an application p...
A REST API (also called a RESTful API or RESTful web API) is an application p...A REST API (also called a RESTful API or RESTful web API) is an application p...
A REST API (also called a RESTful API or RESTful web API) is an application p...
Kongu Engineering College, Perundurai, Erode
 
SOA and Monolith Architecture - Micro Services.pptx
SOA and Monolith Architecture - Micro Services.pptxSOA and Monolith Architecture - Micro Services.pptx
SOA and Monolith Architecture - Micro Services.pptx
Kongu Engineering College, Perundurai, Erode
 
Application Layer.pptx
Application Layer.pptxApplication Layer.pptx
Navigation Bar.pptx
Navigation Bar.pptxNavigation Bar.pptx
nested_Object as Parameter & Recursion_Later_commamd.pptx
nested_Object as Parameter  & Recursion_Later_commamd.pptxnested_Object as Parameter  & Recursion_Later_commamd.pptx
nested_Object as Parameter & Recursion_Later_commamd.pptx
Kongu Engineering College, Perundurai, Erode
 
Chapter 3.pdf
Chapter 3.pdfChapter 3.pdf
Introduction to Social Media and Social Networks.pdf
Introduction to Social Media and Social Networks.pdfIntroduction to Social Media and Social Networks.pdf
Introduction to Social Media and Social Networks.pdf
Kongu Engineering College, Perundurai, Erode
 
Dimensions of elements.pdf
Dimensions of elements.pdfDimensions of elements.pdf
CSS Positioning Elements.pdf
CSS Positioning Elements.pdfCSS Positioning Elements.pdf
CSS Positioning Elements.pdf
Kongu Engineering College, Perundurai, Erode
 
Random number generation_upload.pdf
Random number generation_upload.pdfRandom number generation_upload.pdf
Random number generation_upload.pdf
Kongu Engineering College, Perundurai, Erode
 
JavaScript_introduction_upload.pdf
JavaScript_introduction_upload.pdfJavaScript_introduction_upload.pdf
JavaScript_introduction_upload.pdf
Kongu Engineering College, Perundurai, Erode
 
Computer Networks: Quality of service
Computer Networks: Quality of serviceComputer Networks: Quality of service
Computer Networks: Quality of service
Kongu Engineering College, Perundurai, Erode
 
Transport layer protocols : Simple Protocol , Stop and Wait Protocol , Go-Bac...
Transport layer protocols : Simple Protocol , Stop and Wait Protocol , Go-Bac...Transport layer protocols : Simple Protocol , Stop and Wait Protocol , Go-Bac...
Transport layer protocols : Simple Protocol , Stop and Wait Protocol , Go-Bac...
Kongu Engineering College, Perundurai, Erode
 
Transport layer services
Transport layer servicesTransport layer services
Transport layer protocols : TCP and UDP
Transport layer protocols  : TCP and UDPTransport layer protocols  : TCP and UDP
Transport layer protocols : TCP and UDP
Kongu Engineering College, Perundurai, Erode
 

More from Kongu Engineering College, Perundurai, Erode (20)

Introduction to Spring & Spring BootFramework
Introduction to Spring  & Spring BootFrameworkIntroduction to Spring  & Spring BootFramework
Introduction to Spring & Spring BootFramework
 
A REST API (also called a RESTful API or RESTful web API) is an application p...
A REST API (also called a RESTful API or RESTful web API) is an application p...A REST API (also called a RESTful API or RESTful web API) is an application p...
A REST API (also called a RESTful API or RESTful web API) is an application p...
 
SOA and Monolith Architecture - Micro Services.pptx
SOA and Monolith Architecture - Micro Services.pptxSOA and Monolith Architecture - Micro Services.pptx
SOA and Monolith Architecture - Micro Services.pptx
 
Application Layer.pptx
Application Layer.pptxApplication Layer.pptx
Application Layer.pptx
 
Node_basics.pptx
Node_basics.pptxNode_basics.pptx
Node_basics.pptx
 
Navigation Bar.pptx
Navigation Bar.pptxNavigation Bar.pptx
Navigation Bar.pptx
 
Bootstarp installation.pptx
Bootstarp installation.pptxBootstarp installation.pptx
Bootstarp installation.pptx
 
nested_Object as Parameter & Recursion_Later_commamd.pptx
nested_Object as Parameter  & Recursion_Later_commamd.pptxnested_Object as Parameter  & Recursion_Later_commamd.pptx
nested_Object as Parameter & Recursion_Later_commamd.pptx
 
Chapter 3.pdf
Chapter 3.pdfChapter 3.pdf
Chapter 3.pdf
 
Introduction to Social Media and Social Networks.pdf
Introduction to Social Media and Social Networks.pdfIntroduction to Social Media and Social Networks.pdf
Introduction to Social Media and Social Networks.pdf
 
Dropdown Menu or Combo List.pdf
Dropdown Menu or Combo List.pdfDropdown Menu or Combo List.pdf
Dropdown Menu or Combo List.pdf
 
div tag.pdf
div tag.pdfdiv tag.pdf
div tag.pdf
 
Dimensions of elements.pdf
Dimensions of elements.pdfDimensions of elements.pdf
Dimensions of elements.pdf
 
CSS Positioning Elements.pdf
CSS Positioning Elements.pdfCSS Positioning Elements.pdf
CSS Positioning Elements.pdf
 
Random number generation_upload.pdf
Random number generation_upload.pdfRandom number generation_upload.pdf
Random number generation_upload.pdf
 
JavaScript_introduction_upload.pdf
JavaScript_introduction_upload.pdfJavaScript_introduction_upload.pdf
JavaScript_introduction_upload.pdf
 
Computer Networks: Quality of service
Computer Networks: Quality of serviceComputer Networks: Quality of service
Computer Networks: Quality of service
 
Transport layer protocols : Simple Protocol , Stop and Wait Protocol , Go-Bac...
Transport layer protocols : Simple Protocol , Stop and Wait Protocol , Go-Bac...Transport layer protocols : Simple Protocol , Stop and Wait Protocol , Go-Bac...
Transport layer protocols : Simple Protocol , Stop and Wait Protocol , Go-Bac...
 
Transport layer services
Transport layer servicesTransport layer services
Transport layer services
 
Transport layer protocols : TCP and UDP
Transport layer protocols  : TCP and UDPTransport layer protocols  : TCP and UDP
Transport layer protocols : TCP and UDP
 

Recently uploaded

Sachpazis:Terzaghi Bearing Capacity Estimation in simple terms with Calculati...
Sachpazis:Terzaghi Bearing Capacity Estimation in simple terms with Calculati...Sachpazis:Terzaghi Bearing Capacity Estimation in simple terms with Calculati...
Sachpazis:Terzaghi Bearing Capacity Estimation in simple terms with Calculati...
Dr.Costas Sachpazis
 
Cosmetic shop management system project report.pdf
Cosmetic shop management system project report.pdfCosmetic shop management system project report.pdf
Cosmetic shop management system project report.pdf
Kamal Acharya
 
CME397 Surface Engineering- Professional Elective
CME397 Surface Engineering- Professional ElectiveCME397 Surface Engineering- Professional Elective
CME397 Surface Engineering- Professional Elective
karthi keyan
 
power quality voltage fluctuation UNIT - I.pptx
power quality voltage fluctuation UNIT - I.pptxpower quality voltage fluctuation UNIT - I.pptx
power quality voltage fluctuation UNIT - I.pptx
ViniHema
 
Final project report on grocery store management system..pdf
Final project report on grocery store management system..pdfFinal project report on grocery store management system..pdf
Final project report on grocery store management system..pdf
Kamal Acharya
 
English lab ppt no titlespecENG PPTt.pdf
English lab ppt no titlespecENG PPTt.pdfEnglish lab ppt no titlespecENG PPTt.pdf
English lab ppt no titlespecENG PPTt.pdf
BrazilAccount1
 
The Benefits and Techniques of Trenchless Pipe Repair.pdf
The Benefits and Techniques of Trenchless Pipe Repair.pdfThe Benefits and Techniques of Trenchless Pipe Repair.pdf
The Benefits and Techniques of Trenchless Pipe Repair.pdf
Pipe Restoration Solutions
 
ethical hacking-mobile hacking methods.ppt
ethical hacking-mobile hacking methods.pptethical hacking-mobile hacking methods.ppt
ethical hacking-mobile hacking methods.ppt
Jayaprasanna4
 
Hierarchical Digital Twin of a Naval Power System
Hierarchical Digital Twin of a Naval Power SystemHierarchical Digital Twin of a Naval Power System
Hierarchical Digital Twin of a Naval Power System
Kerry Sado
 
space technology lecture notes on satellite
space technology lecture notes on satellitespace technology lecture notes on satellite
space technology lecture notes on satellite
ongomchris
 
Design and Analysis of Algorithms-DP,Backtracking,Graphs,B&B
Design and Analysis of Algorithms-DP,Backtracking,Graphs,B&BDesign and Analysis of Algorithms-DP,Backtracking,Graphs,B&B
Design and Analysis of Algorithms-DP,Backtracking,Graphs,B&B
Sreedhar Chowdam
 
WATER CRISIS and its solutions-pptx 1234
WATER CRISIS and its solutions-pptx 1234WATER CRISIS and its solutions-pptx 1234
WATER CRISIS and its solutions-pptx 1234
AafreenAbuthahir2
 
Runway Orientation Based on the Wind Rose Diagram.pptx
Runway Orientation Based on the Wind Rose Diagram.pptxRunway Orientation Based on the Wind Rose Diagram.pptx
Runway Orientation Based on the Wind Rose Diagram.pptx
SupreethSP4
 
AP LAB PPT.pdf ap lab ppt no title specific
AP LAB PPT.pdf ap lab ppt no title specificAP LAB PPT.pdf ap lab ppt no title specific
AP LAB PPT.pdf ap lab ppt no title specific
BrazilAccount1
 
road safety engineering r s e unit 3.pdf
road safety engineering  r s e unit 3.pdfroad safety engineering  r s e unit 3.pdf
road safety engineering r s e unit 3.pdf
VENKATESHvenky89705
 
J.Yang, ICLR 2024, MLILAB, KAIST AI.pdf
J.Yang,  ICLR 2024, MLILAB, KAIST AI.pdfJ.Yang,  ICLR 2024, MLILAB, KAIST AI.pdf
J.Yang, ICLR 2024, MLILAB, KAIST AI.pdf
MLILAB
 
Architectural Portfolio Sean Lockwood
Architectural Portfolio Sean LockwoodArchitectural Portfolio Sean Lockwood
Architectural Portfolio Sean Lockwood
seandesed
 
Gen AI Study Jams _ For the GDSC Leads in India.pdf
Gen AI Study Jams _ For the GDSC Leads in India.pdfGen AI Study Jams _ For the GDSC Leads in India.pdf
Gen AI Study Jams _ For the GDSC Leads in India.pdf
gdsczhcet
 
CFD Simulation of By-pass Flow in a HRSG module by R&R Consult.pptx
CFD Simulation of By-pass Flow in a HRSG module by R&R Consult.pptxCFD Simulation of By-pass Flow in a HRSG module by R&R Consult.pptx
CFD Simulation of By-pass Flow in a HRSG module by R&R Consult.pptx
R&R Consult
 
block diagram and signal flow graph representation
block diagram and signal flow graph representationblock diagram and signal flow graph representation
block diagram and signal flow graph representation
Divya Somashekar
 

Recently uploaded (20)

Sachpazis:Terzaghi Bearing Capacity Estimation in simple terms with Calculati...
Sachpazis:Terzaghi Bearing Capacity Estimation in simple terms with Calculati...Sachpazis:Terzaghi Bearing Capacity Estimation in simple terms with Calculati...
Sachpazis:Terzaghi Bearing Capacity Estimation in simple terms with Calculati...
 
Cosmetic shop management system project report.pdf
Cosmetic shop management system project report.pdfCosmetic shop management system project report.pdf
Cosmetic shop management system project report.pdf
 
CME397 Surface Engineering- Professional Elective
CME397 Surface Engineering- Professional ElectiveCME397 Surface Engineering- Professional Elective
CME397 Surface Engineering- Professional Elective
 
power quality voltage fluctuation UNIT - I.pptx
power quality voltage fluctuation UNIT - I.pptxpower quality voltage fluctuation UNIT - I.pptx
power quality voltage fluctuation UNIT - I.pptx
 
Final project report on grocery store management system..pdf
Final project report on grocery store management system..pdfFinal project report on grocery store management system..pdf
Final project report on grocery store management system..pdf
 
English lab ppt no titlespecENG PPTt.pdf
English lab ppt no titlespecENG PPTt.pdfEnglish lab ppt no titlespecENG PPTt.pdf
English lab ppt no titlespecENG PPTt.pdf
 
The Benefits and Techniques of Trenchless Pipe Repair.pdf
The Benefits and Techniques of Trenchless Pipe Repair.pdfThe Benefits and Techniques of Trenchless Pipe Repair.pdf
The Benefits and Techniques of Trenchless Pipe Repair.pdf
 
ethical hacking-mobile hacking methods.ppt
ethical hacking-mobile hacking methods.pptethical hacking-mobile hacking methods.ppt
ethical hacking-mobile hacking methods.ppt
 
Hierarchical Digital Twin of a Naval Power System
Hierarchical Digital Twin of a Naval Power SystemHierarchical Digital Twin of a Naval Power System
Hierarchical Digital Twin of a Naval Power System
 
space technology lecture notes on satellite
space technology lecture notes on satellitespace technology lecture notes on satellite
space technology lecture notes on satellite
 
Design and Analysis of Algorithms-DP,Backtracking,Graphs,B&B
Design and Analysis of Algorithms-DP,Backtracking,Graphs,B&BDesign and Analysis of Algorithms-DP,Backtracking,Graphs,B&B
Design and Analysis of Algorithms-DP,Backtracking,Graphs,B&B
 
WATER CRISIS and its solutions-pptx 1234
WATER CRISIS and its solutions-pptx 1234WATER CRISIS and its solutions-pptx 1234
WATER CRISIS and its solutions-pptx 1234
 
Runway Orientation Based on the Wind Rose Diagram.pptx
Runway Orientation Based on the Wind Rose Diagram.pptxRunway Orientation Based on the Wind Rose Diagram.pptx
Runway Orientation Based on the Wind Rose Diagram.pptx
 
AP LAB PPT.pdf ap lab ppt no title specific
AP LAB PPT.pdf ap lab ppt no title specificAP LAB PPT.pdf ap lab ppt no title specific
AP LAB PPT.pdf ap lab ppt no title specific
 
road safety engineering r s e unit 3.pdf
road safety engineering  r s e unit 3.pdfroad safety engineering  r s e unit 3.pdf
road safety engineering r s e unit 3.pdf
 
J.Yang, ICLR 2024, MLILAB, KAIST AI.pdf
J.Yang,  ICLR 2024, MLILAB, KAIST AI.pdfJ.Yang,  ICLR 2024, MLILAB, KAIST AI.pdf
J.Yang, ICLR 2024, MLILAB, KAIST AI.pdf
 
Architectural Portfolio Sean Lockwood
Architectural Portfolio Sean LockwoodArchitectural Portfolio Sean Lockwood
Architectural Portfolio Sean Lockwood
 
Gen AI Study Jams _ For the GDSC Leads in India.pdf
Gen AI Study Jams _ For the GDSC Leads in India.pdfGen AI Study Jams _ For the GDSC Leads in India.pdf
Gen AI Study Jams _ For the GDSC Leads in India.pdf
 
CFD Simulation of By-pass Flow in a HRSG module by R&R Consult.pptx
CFD Simulation of By-pass Flow in a HRSG module by R&R Consult.pptxCFD Simulation of By-pass Flow in a HRSG module by R&R Consult.pptx
CFD Simulation of By-pass Flow in a HRSG module by R&R Consult.pptx
 
block diagram and signal flow graph representation
block diagram and signal flow graph representationblock diagram and signal flow graph representation
block diagram and signal flow graph representation
 

Connect to NoSQL Database using Node JS.pptx

  • 1. Connect to NoSQL Database using Node JS Dr.T.Abirami Associate Professor Department of IT Kongu Engineering College Dr.T.Abirami / Associate Professor / Department of IT/ KEC
  • 2. What Is a Database • A database is an organized collection of structured information, or data, typically stored electronically in a computer system Dr.T.Abirami / Associate Professor / Department of IT/ KEC
  • 3. Types of databases • Centralised database. • Distributed database. • Personal database. • End-user database. • Commercial database. • NoSQL database. • Operational database. • Relational database. • Cloud database. • Object-oriented database. • Graph database. Dr.T.Abirami / Associate Professor / Department of IT/ KEC
  • 4. 1. Centralised Database • The information(data) is stored at a centralized location and the users from different locations can access this data. • This type of database contains application procedures that help the users to access the data even from a remote location. Dr.T.Abirami / Associate Professor / Department of IT/ KEC
  • 5. Distributed Database • Just opposite of the centralized database concept, • The data is not at one place and is distributed at various sites of an organization. These sites are connected to each other with the help of communication links which helps them to access the distributed data easily. Dr.T.Abirami / Associate Professor / Department of IT/ KEC
  • 6. Introduction to NoSQL •NoSQL is a type of database management system (DBMS) that is designed to handle and store large volumes of unstructured and semi- structured data. •NoSQL originally referred to “non-SQL” or “non- relational” databases Dr.T.Abirami / Associate Professor / Department of IT/ KEC
  • 7. NoSQL Database •It is used for large sets of distributed data. •There are some big data performance issues which are effectively handled by relational databases, such kind of issues are easily managed by NoSQL databases. •There are very efficient in analyzing large size unstructured data that may be stored at multiple virtual servers of the cloud. Dr.T.Abirami / Associate Professor / Department of IT/ KEC
  • 8. Cloud and Database • A cloud is a network of remote servers that are connected to the internet, and are used to store, manage and process data. • Cloud services can be divided into three categories: • Infrastructure as a Service (IaaS), • Platform as a Service (PaaS) and • Software as a Service (SaaS). T • he main benefit of cloud computing is its scalability, as well as its ability to provide on-demand access to computing resources and services. Dr.T.Abirami / Associate Professor / Department of IT/ KEC
  • 9. Cloud and Database • A database is a collection of data that is organized in a specific way and can be accessed, managed and updated by a software application. • Databases are used to store and retrieve data in an efficient and organized manner. • There are different types of databases, such as • relational databases (MySQL, Oracle, MS SQL), NoSQL databases (MongoDB, Cassandra, Redis) and graph databases (Neo4j). Dr.T.Abirami / Associate Professor / Department of IT/ KEC
  • 10. Cloud and Database • cloud is a type of technology that provides access to remote servers and computing resources • database is a collection of data that is organized and managed by a specific software. • While they are different, they can be used together, such as running a database in a cloud environment. Dr.T.Abirami / Associate Professor / Department of IT/ KEC
  • 11. Dr.T.Abirami / Associate Professor / Department of IT/ KEC
  • 12. JSON / JavaScript Object Notation Basics • It is a text-based data exchange format. • It is a collection of key-value pairs • where the key must be a string type, and the value can be of any of the following types: • Number • String • Boolean • Array • Object • null Dr.T.Abirami / Associate Professor / Department of IT/ KEC
  • 13. Simple JSON Data { "name": "Alex C", "age": 22, "city": “Erode" } Dr.T.Abirami / Associate Professor / Department of IT/ KEC
  • 14. [ { "name": "Alex C", "age": 24, "city": “Erode" }, { "name": "John G", "age": 40, "city": "Washington" }, { "name": "Bala T", "age": 22, "city": "Bangalore" } ] JSON Data with a Collection of Ordered Records Dr.T.Abirami / Associate Professor / Department of IT/ KEC
  • 15. Employee Data in JSON Format { "name": "Aleix Melon", "id": "E00245", "role": ["Dev", "DBA"], "age": 23, "doj": "11-12-2019", "married": false, "address": { "street": "32, Laham St.", "city": "Innsbruck", "country": "Austria" }, "referred-by": "E0012" } Dr.T.Abirami / Associate Professor / Department of IT/ KEC
  • 16. [ { "name": "Aleix Melon", "id": "E00245", "role": ["Dev", "DBA"], "age": 23, "doj": "11-12-2019", "married": false, "address": { "street": "32, Laham St.", "city": "Innsbruck", "country": "Austria" }, "referred-by": "E0012" }, { "name": "Bob Washington", "id": "E01245", "role": ["HR"], "age": 43, "doj": "10-06-2010", "married": true, "address": { "street": "45, Abraham Lane.", "city": "Washington", "country": "USA" }, "referred-by": null } ] An Array of Employee Data in JSON Format Dr.T.Abirami / Associate Professor / Department of IT/ KEC
  • 17. File: first.json {"employees":[ {"name":"Sonoo", "email":"sonoojaiswal1987@gmail.com"}, {"name":"Rahul", "email":"rahul32@gmail.com"}, {"name":"John", "email":"john32bob@gmail.com"} ]} Dr.T.Abirami / Associate Professor / Department of IT/ KEC
  • 18. MongoDB • MongoDB is a NoSQL database. • MongoDB is an open source, document oriented database that stores data in form of documents (key and value pairs). Dr.T.Abirami / Associate Professor / Department of IT/ KEC
  • 19. Fields (key and value pairs) are stored in document, documents are stored in collection and collections are stored in database. Dr.T.Abirami / Associate Professor / Department of IT/ KEC
  • 20. Dr.T.Abirami / Associate Professor / Department of IT/ KEC
  • 21. CRUD operations in MongoDB • Create: This operation allows you to insert new documents into a MongoDB collection. A document is a data structure that consists of field- value pairs, similar to a JSON object. • Read: This operation allows you to retrieve data from a MongoDB collection. You can retrieve a single document or multiple documents that match a specific query. • Update: This operation allows you to modify existing documents in a MongoDB collection. You can update one or multiple documents that match a specific query. • Delete: This operation allows you to remove documents from a MongoDB collection. You can delete a single document or multiple documents that match a specific query. Dr.T.Abirami / Associate Professor / Department of IT/ KEC
  • 22. Download MongoDB • download MongoDB from the official website: https://www.mongodb.com/download- center/community. • MongoDB driver for our programming language. • using the official MongoDB driver for Node.js. • You can install it by running the following command: npm install mongodb npm install mongoose Dr.T.Abirami / Associate Professor / Department of IT/ KEC
  • 23. Dr.T.Abirami / Associate Professor / Department of IT/ KEC
  • 24. Dr.T.Abirami / Associate Professor / Department of IT/ KEC
  • 25. Dr.T.Abirami / Associate Professor / Department of IT/ KEC
  • 26. Dr.T.Abirami / Associate Professor / Department of IT/ KEC
  • 27. Step 1 : Check properly installed or not Open cmd and type: • mongod -version • mongo -version Dr.T.Abirami / Associate Professor / Department of IT/ KEC
  • 28. Step 2 : Server on & Client on Open two separate cmd and type: One for server & another for client • mongod • mongo Dr.T.Abirami / Associate Professor / Department of IT/ KEC
  • 29. Within Mongo (Client) window Shows databases show dbs Ans: admin 0.000GB config 0.000GB local 0.000GB Dr.T.Abirami / Associate Professor / Department of IT/ KEC
  • 30. Create database use Employee Ans: switched to db Employee Dr.T.Abirami / Associate Professor / Department of IT/ KEC
  • 31. Create collection /table db.createCollection("posts") Ans: { "ok" : 1 } Dr.T.Abirami / Associate Professor / Department of IT/ KEC
  • 32. Insert data db.posts.insertOne({name:"abi"}) Ans: { "acknowledged" : true, "insertedId" : ObjectId("643e391ee1f9ddc511f3beaf") } Dr.T.Abirami / Associate Professor / Department of IT/ KEC
  • 33. View / Select /find a data db.posts.find() Ans: { "_id" : ObjectId("643e391ee1f9ddc511f3beaf"), "name" : "abi" } Dr.T.Abirami / Associate Professor / Department of IT/ KEC
  • 34. Update command db.posts.update({name:"abi"},{$set:{name:"helloword"}}) Ans: WriteResult({ "nMatched" : 1, "nUpserted" : 0, "nModified" : 1 }) Dr.T.Abirami / Associate Professor / Department of IT/ KEC
  • 35. Delete command db.posts.deleteOne({ name: "helloword" }) Ans: { "acknowledged" : true, "deletedCount" : 1 } Dr.T.Abirami / Associate Professor / Department of IT/ KEC
  • 36. MongoDB – sort() Method • The sort() method specifies the order in which the query returns the matching documents from the given collection. db.Collection_Name.sort({filed_name:1 or -1}) db.student.find().sort({age:1}) • Parameter: The value is 1 or -1 that specifies an ascending or descending sort respectively. The type of parameter is a document. Dr.T.Abirami / Associate Professor / Department of IT/ KEC
  • 37. Connect Node.js with NoSQL MongoDB Database Install mongoose: • Step 1: install the mongoose module. You can install this package by using this command. npm install mongoose • Step 2: Now you can import the mongoose module in your file using: const mongoose = require('mongoose'); Dr.T.Abirami / Associate Professor / Department of IT/ KEC
  • 38. Mongoose Module Introduction •It provides several functions in order to manipulate the documents of the collection of the MongoDB database Dr.T.Abirami / Associate Professor / Department of IT/ KEC
  • 39. Mongoose • Mongoose is an Object Data Modeling (ODM) tool designed to work in an asynchronous environment. • Mongoose schema as a blueprint for defining the structure of a Mongoose model that maps directly to a MongoDB collection. Dr.T.Abirami / Associate Professor / Department of IT/ KEC
  • 40. • -->unifiedtopology : DeprecationWarning: current Server Discovery and Monitoring engine is deprecated, and will be removed in a future version. • To use the new Server Discover and Monitoring engine, pass option { useUnifiedTopology: true } to the MongoClient constructor. • -->usenewurlparser : DeprecationWarning: current URL string parser is deprecated, and will be removed in a future version. To use the new parser, pass option { useNewUrlParser: true } to MongoClient.connect. Dr.T.Abirami / Associate Professor / Department of IT/ KEC
  • 41. Step 1 : create schema and set model const mongoose =require("mongoose") const url = "mongodb://localhost:27017/project"; const name = new mongoose.Schema({ name: String, age:Number, rollno:String }); const Name= mongoose.model('Name',name) Dr.T.Abirami / Associate Professor / Department of IT/ KEC
  • 42. const db = async() =>{ try{ console.log("entered") const data=await mongoose.connect(url, { useNewUrlParser: true, useUnifiedTopology: true, family: 4, } ) console.log("connected") } catch(err){ console.log(err) } } db() Step 2 : create connection Dr.T.Abirami / Associate Professor / Department of IT/ KEC
  • 43. Insert data const insertdata=async()=>{ const cat = new Name({ name: 'Zildjian' , age:25, rollno:"21ITR089"}); cat.save().then(() => console.log('Saved in db')); } Insertdata() Dr.T.Abirami / Associate Professor / Department of IT/ KEC
  • 44. Update query const updatedata=async() => { const filter = { name: "Zildjian" }; const update = { age: 97 }; let doc = await Name.findOneAndUpdate(filter, update); console.log(doc.name); // 'Luke Skywalker' console.log(doc.age); // undefined } updatedata() Dr.T.Abirami / Associate Professor / Department of IT/ KEC
  • 45. Delete query const deletedata=async() => { await Name.deleteMany({name: 'Zildjian'}); } deletedata() Dr.T.Abirami / Associate Professor / Department of IT/ KEC
  • 46. Reference • https://masteringjs.io/mongoose • https://www.mongodb.com/docs/manual/tutorial/install-mongodb- on-windows/ • https://mongoosejs.com/docs/5.x/docs/tutorials/findoneandupdate. html Dr.T.Abirami / Associate Professor / Department of IT/ KEC