SlideShare a Scribd company logo
Connect to NoSQL Database
using Node JS
What Is a Database
•A database is an organized collection of structured
information, or data, typically stored electronically in
a computer system
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.
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.
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.
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
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.
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.
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).
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.
Connect to NoSQL Database (MongoDB) using Node JS & Connect Node.js with NoSQL MongoDB Database
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
Simple JSON Data
{
"name": "Alex C",
"age": 22,
"city": “Erode"
}
[
{
"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
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"
}
[ { "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
File: first.json
{"employees":[
{"name":"Sonoo", "email":"sonoojaiswal1987@gmail.com"},
{"name":"Rahul", "email":"rahul32@gmail.com"},
{"name":"John", "email":"john32bob@gmail.com"}
]}
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).
Fields (key and value pairs) are stored in document, documents are
stored in collection and collections are stored in database.
Connect to NoSQL Database (MongoDB) using Node JS & Connect Node.js with NoSQL MongoDB Database
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.
Download MongoDB
•download MongoDB from the official website:
https://www.mongodb.com/download-center/communi
ty
.
• 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
Connect to NoSQL Database (MongoDB) using Node JS & Connect Node.js with NoSQL MongoDB Database
Connect to NoSQL Database (MongoDB) using Node JS & Connect Node.js with NoSQL MongoDB Database
Connect to NoSQL Database (MongoDB) using Node JS & Connect Node.js with NoSQL MongoDB Database
Connect to NoSQL Database (MongoDB) using Node JS & Connect Node.js with NoSQL MongoDB Database
Step 1 : Check properly installed or not
Open cmd and type:
•mongod -version
•mongo -version
Step 2 : Server on & Client on
Open two separate cmd and type: One for server & another for
client
• mongod
• mongo
Within Mongo (Client) window
Shows databases
show dbs
Ans:
admin 0.000GB
config 0.000GB
local 0.000GB
Create database
use Employee
Ans:
switched to db Employee
Create collection /table
db.createCollection("posts")
Ans:
{ "ok" : 1 }
Insert data
db.posts.insertOne({name:"abi"})
Ans:
{
"acknowledged" : true,
"insertedId" :
ObjectId("643e391ee1f9ddc511f3beaf")
}
View / Select /find a data
db.posts.find()
Ans:
{ "_id" : ObjectId("643e391ee1f9ddc511f3beaf"),
"name" : "abi" }
Update command
db.posts.update({name:"abi"},{$set:{name:"helloword"}})
Ans:
WriteResult({ "nMatched" : 1, "nUpserted" : 0, "nModified" : 1
})
Delete command
db.posts.deleteOne({ name: "helloword" })
Ans:
{ "acknowledged" : true, "deletedCount" : 1 }
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.
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');
Mongoose Module Introduction
•It provides several functions in order to
manipulate the documents of the collection of
the MongoDB database
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.
• -->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.
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)
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
Insert data
const insertdata=async()=>{
const cat = new Name({ name: 'Zildjian' , age:25, rollno:"21ITR089"});
cat.save().then(() => console.log('Saved in db'));
}
Insertdata()
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()
Delete query
const deletedata=async() => {
await Name.deleteMany({name: 'Zildjian'});
}
deletedata()
Reference
• https://masteringjs.io/mongoose
• https://www.mongodb.com/docs/manual/tutorial/install-mongodb-o
n-windows/
• https://mongoosejs.com/docs/5.x/docs/tutorials/findoneandupdate.
html
• https://www.youtube.com/watch?v=gB6WLkSrtJk

More Related Content

Similar to Connect to NoSQL Database (MongoDB) using Node JS & Connect Node.js with NoSQL MongoDB Database (20)

3-Mongodb and Mapreduce Programming.pdf
3-Mongodb and Mapreduce Programming.pdf3-Mongodb and Mapreduce Programming.pdf
3-Mongodb and Mapreduce Programming.pdf
MarianJRuben
 
Talk MongoDB - Amil
Talk MongoDB - AmilTalk MongoDB - Amil
Talk MongoDB - Amil
removed_b0e2342824f6227286f54ba461ebc0fe
 
NOSQL and MongoDB Database
NOSQL and MongoDB DatabaseNOSQL and MongoDB Database
NOSQL and MongoDB Database
Tariqul islam
 
Mongo db
Mongo dbMongo db
Mongo db
Gyanendra Yadav
 
Mongodb
MongodbMongodb
Mongodb
ASEEMSRIVASTAVA22
 
Mongo Bb - NoSQL tutorial
Mongo Bb - NoSQL tutorialMongo Bb - NoSQL tutorial
Mongo Bb - NoSQL tutorial
Mohan Rathour
 
Mongodb
MongodbMongodb
Mongodb
ichangbai
 
MongoDB_ppt.pptx
MongoDB_ppt.pptxMongoDB_ppt.pptx
MongoDB_ppt.pptx
1AP18CS037ShirishKul
 
Mongodb
MongodbMongodb
Mongodb
kalai s
 
1428393873 mhkx3 ln
1428393873 mhkx3 ln1428393873 mhkx3 ln
1428393873 mhkx3 ln
WilfredodelaCernaJr
 
Kalp Corporate MongoDB Tutorials
Kalp Corporate MongoDB TutorialsKalp Corporate MongoDB Tutorials
Kalp Corporate MongoDB Tutorials
Kalp Corporate
 
Introduction to MongoDB
Introduction to MongoDBIntroduction to MongoDB
Introduction to MongoDB
S.Shayan Daneshvar
 
Einführung in MongoDB
Einführung in MongoDBEinführung in MongoDB
Einführung in MongoDB
NETUserGroupBern
 
Mongodb
MongodbMongodb
Mongodb
Paulo Fagundes
 
MongoDB NoSQL database a deep dive -MyWhitePaper
MongoDB  NoSQL database a deep dive -MyWhitePaperMongoDB  NoSQL database a deep dive -MyWhitePaper
MongoDB NoSQL database a deep dive -MyWhitePaper
Rajesh Kumar
 
Big data technology unit 3
Big data technology unit 3Big data technology unit 3
Big data technology unit 3
RojaT4
 
Mongodb - NoSql Database
Mongodb - NoSql DatabaseMongodb - NoSql Database
Mongodb - NoSql Database
Prashant Gupta
 
The Little MongoDB Book - Karl Seguin
The Little MongoDB Book - Karl SeguinThe Little MongoDB Book - Karl Seguin
The Little MongoDB Book - Karl Seguin
Paulo Fagundes
 
Mongo DB
Mongo DBMongo DB
Mongo DB
SRM University Delhi-NCR sonepat
 
Mongo db
Mongo dbMongo db
Mongo db
AbhiKhurana8
 

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

Introduction to Generative AI refers to a subset of artificial intelligence
Introduction to Generative AI refers to a subset of artificial intelligenceIntroduction to Generative AI refers to a subset of artificial intelligence
Introduction to Generative AI refers to a subset of artificial intelligence
Kongu Engineering College, Perundurai, Erode
 
Introduction to Microsoft Power BI is a business analytics service
Introduction to Microsoft Power BI is a business analytics serviceIntroduction to Microsoft Power BI is a business analytics service
Introduction to Microsoft Power BI is a business analytics service
Kongu Engineering College, Perundurai, Erode
 
concept of server-side JavaScript / JS Framework: NODEJS
concept of server-side JavaScript / JS Framework: NODEJSconcept of server-side JavaScript / JS Framework: NODEJS
concept of server-side JavaScript / JS Framework: NODEJS
Kongu Engineering College, Perundurai, Erode
 
Node.js web-based Example :Run a local server in order to start using node.js...
Node.js web-based Example :Run a local server in order to start using node.js...Node.js web-based Example :Run a local server in order to start using node.js...
Node.js web-based Example :Run a local server in order to start using node.js...
Kongu Engineering College, Perundurai, Erode
 
Concepts of Satellite Communication and types and its applications
Concepts of Satellite Communication  and types and its applicationsConcepts of Satellite Communication  and types and its applications
Concepts of Satellite Communication and types and its applications
Kongu Engineering College, Perundurai, Erode
 
Concepts of Mobile Communication Wireless LANs, Bluetooth , HiperLAN
Concepts of Mobile Communication Wireless LANs, Bluetooth , HiperLANConcepts of Mobile Communication Wireless LANs, Bluetooth , HiperLAN
Concepts of Mobile Communication Wireless LANs, Bluetooth , HiperLAN
Kongu Engineering College, Perundurai, Erode
 
Web Technology Introduction framework.pptx
Web Technology Introduction framework.pptxWeb Technology Introduction framework.pptx
Web Technology Introduction framework.pptx
Kongu Engineering College, Perundurai, Erode
 
Computer Network - Unicast Routing Distance vector Link state vector
Computer Network - Unicast Routing Distance vector Link state vectorComputer Network - Unicast Routing Distance vector Link state vector
Computer Network - Unicast Routing Distance vector Link state vector
Kongu Engineering College, Perundurai, Erode
 
Android SQLite database oriented application development
Android SQLite database oriented application developmentAndroid SQLite database oriented application development
Android SQLite database oriented application development
Kongu Engineering College, Perundurai, Erode
 
Android Application Development Programming
Android Application Development ProgrammingAndroid Application Development Programming
Android Application Development Programming
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
Application Layer.pptx
Kongu Engineering College, Perundurai, Erode
 
Node_basics.pptx
Node_basics.pptxNode_basics.pptx
Node_basics.pptx
Kongu Engineering College, Perundurai, Erode
 
Navigation Bar.pptx
Navigation Bar.pptxNavigation Bar.pptx
Navigation Bar.pptx
Kongu Engineering College, Perundurai, Erode
 
Bootstarp installation.pptx
Bootstarp installation.pptxBootstarp installation.pptx
Bootstarp installation.pptx
Kongu Engineering College, Perundurai, Erode
 
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
Chapter 3.pdf
Kongu Engineering College, Perundurai, Erode
 
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
 
Ad

Recently uploaded (20)

“State-space Models vs. Transformers for Ultra-low-power Edge AI,” a Presenta...
“State-space Models vs. Transformers for Ultra-low-power Edge AI,” a Presenta...“State-space Models vs. Transformers for Ultra-low-power Edge AI,” a Presenta...
“State-space Models vs. Transformers for Ultra-low-power Edge AI,” a Presenta...
Edge AI and Vision Alliance
 
Cisco ISE Performance, Scalability and Best Practices.pdf
Cisco ISE Performance, Scalability and Best Practices.pdfCisco ISE Performance, Scalability and Best Practices.pdf
Cisco ISE Performance, Scalability and Best Practices.pdf
superdpz
 
Introduction to Internet of things .ppt.
Introduction to Internet of things .ppt.Introduction to Internet of things .ppt.
Introduction to Internet of things .ppt.
hok12341073
 
Trends Artificial Intelligence - Mary Meeker
Trends Artificial Intelligence - Mary MeekerTrends Artificial Intelligence - Mary Meeker
Trends Artificial Intelligence - Mary Meeker
Clive Dickens
 
Domino IQ – Was Sie erwartet, erste Schritte und Anwendungsfälle
Domino IQ – Was Sie erwartet, erste Schritte und AnwendungsfälleDomino IQ – Was Sie erwartet, erste Schritte und Anwendungsfälle
Domino IQ – Was Sie erwartet, erste Schritte und Anwendungsfälle
panagenda
 
Murdledescargadarkweb.pdfvolumen1 100 elementary
Murdledescargadarkweb.pdfvolumen1 100 elementaryMurdledescargadarkweb.pdfvolumen1 100 elementary
Murdledescargadarkweb.pdfvolumen1 100 elementary
JorgeSemperteguiMont
 
cnc-drilling-dowel-inserting-machine-drillteq-d-510-english.pdf
cnc-drilling-dowel-inserting-machine-drillteq-d-510-english.pdfcnc-drilling-dowel-inserting-machine-drillteq-d-510-english.pdf
cnc-drilling-dowel-inserting-machine-drillteq-d-510-english.pdf
AmirStern2
 
TimeSeries Machine Learning - PyData London 2025
TimeSeries Machine Learning - PyData London 2025TimeSeries Machine Learning - PyData London 2025
TimeSeries Machine Learning - PyData London 2025
Suyash Joshi
 
Kubernetes Security Act Now Before It’s Too Late
Kubernetes Security Act Now Before It’s Too LateKubernetes Security Act Now Before It’s Too Late
Kubernetes Security Act Now Before It’s Too Late
Michael Furman
 
Integration of Utility Data into 3D BIM Models Using a 3D Solids Modeling Wor...
Integration of Utility Data into 3D BIM Models Using a 3D Solids Modeling Wor...Integration of Utility Data into 3D BIM Models Using a 3D Solids Modeling Wor...
Integration of Utility Data into 3D BIM Models Using a 3D Solids Modeling Wor...
Safe Software
 
Artificial Intelligence in the Nonprofit Boardroom.pdf
Artificial Intelligence in the Nonprofit Boardroom.pdfArtificial Intelligence in the Nonprofit Boardroom.pdf
Artificial Intelligence in the Nonprofit Boardroom.pdf
OnBoard
 
Can We Use Rust to Develop Extensions for PostgreSQL? (POSETTE: An Event for ...
Can We Use Rust to Develop Extensions for PostgreSQL? (POSETTE: An Event for ...Can We Use Rust to Develop Extensions for PostgreSQL? (POSETTE: An Event for ...
Can We Use Rust to Develop Extensions for PostgreSQL? (POSETTE: An Event for ...
NTT DATA Technology & Innovation
 
Agentic AI: Beyond the Buzz- LangGraph Studio V2
Agentic AI: Beyond the Buzz- LangGraph Studio V2Agentic AI: Beyond the Buzz- LangGraph Studio V2
Agentic AI: Beyond the Buzz- LangGraph Studio V2
Shashikant Jagtap
 
Oracle Cloud Infrastructure AI Foundations
Oracle Cloud Infrastructure AI FoundationsOracle Cloud Infrastructure AI Foundations
Oracle Cloud Infrastructure AI Foundations
VICTOR MAESTRE RAMIREZ
 
Oracle Cloud and AI Specialization Program
Oracle Cloud and AI Specialization ProgramOracle Cloud and AI Specialization Program
Oracle Cloud and AI Specialization Program
VICTOR MAESTRE RAMIREZ
 
Precisely Demo Showcase: Powering ServiceNow Discovery with Precisely Ironstr...
Precisely Demo Showcase: Powering ServiceNow Discovery with Precisely Ironstr...Precisely Demo Showcase: Powering ServiceNow Discovery with Precisely Ironstr...
Precisely Demo Showcase: Powering ServiceNow Discovery with Precisely Ironstr...
Precisely
 
If You Use Databricks, You Definitely Need FME
If You Use Databricks, You Definitely Need FMEIf You Use Databricks, You Definitely Need FME
If You Use Databricks, You Definitely Need FME
Safe Software
 
Providing an OGC API Processes REST Interface for FME Flow
Providing an OGC API Processes REST Interface for FME FlowProviding an OGC API Processes REST Interface for FME Flow
Providing an OGC API Processes REST Interface for FME Flow
Safe Software
 
Your startup on AWS - How to architect and maintain a Lean and Mean account J...
Your startup on AWS - How to architect and maintain a Lean and Mean account J...Your startup on AWS - How to architect and maintain a Lean and Mean account J...
Your startup on AWS - How to architect and maintain a Lean and Mean account J...
angelo60207
 
Scaling GenAI Inference From Prototype to Production: Real-World Lessons in S...
Scaling GenAI Inference From Prototype to Production: Real-World Lessons in S...Scaling GenAI Inference From Prototype to Production: Real-World Lessons in S...
Scaling GenAI Inference From Prototype to Production: Real-World Lessons in S...
Anish Kumar
 
“State-space Models vs. Transformers for Ultra-low-power Edge AI,” a Presenta...
“State-space Models vs. Transformers for Ultra-low-power Edge AI,” a Presenta...“State-space Models vs. Transformers for Ultra-low-power Edge AI,” a Presenta...
“State-space Models vs. Transformers for Ultra-low-power Edge AI,” a Presenta...
Edge AI and Vision Alliance
 
Cisco ISE Performance, Scalability and Best Practices.pdf
Cisco ISE Performance, Scalability and Best Practices.pdfCisco ISE Performance, Scalability and Best Practices.pdf
Cisco ISE Performance, Scalability and Best Practices.pdf
superdpz
 
Introduction to Internet of things .ppt.
Introduction to Internet of things .ppt.Introduction to Internet of things .ppt.
Introduction to Internet of things .ppt.
hok12341073
 
Trends Artificial Intelligence - Mary Meeker
Trends Artificial Intelligence - Mary MeekerTrends Artificial Intelligence - Mary Meeker
Trends Artificial Intelligence - Mary Meeker
Clive Dickens
 
Domino IQ – Was Sie erwartet, erste Schritte und Anwendungsfälle
Domino IQ – Was Sie erwartet, erste Schritte und AnwendungsfälleDomino IQ – Was Sie erwartet, erste Schritte und Anwendungsfälle
Domino IQ – Was Sie erwartet, erste Schritte und Anwendungsfälle
panagenda
 
Murdledescargadarkweb.pdfvolumen1 100 elementary
Murdledescargadarkweb.pdfvolumen1 100 elementaryMurdledescargadarkweb.pdfvolumen1 100 elementary
Murdledescargadarkweb.pdfvolumen1 100 elementary
JorgeSemperteguiMont
 
cnc-drilling-dowel-inserting-machine-drillteq-d-510-english.pdf
cnc-drilling-dowel-inserting-machine-drillteq-d-510-english.pdfcnc-drilling-dowel-inserting-machine-drillteq-d-510-english.pdf
cnc-drilling-dowel-inserting-machine-drillteq-d-510-english.pdf
AmirStern2
 
TimeSeries Machine Learning - PyData London 2025
TimeSeries Machine Learning - PyData London 2025TimeSeries Machine Learning - PyData London 2025
TimeSeries Machine Learning - PyData London 2025
Suyash Joshi
 
Kubernetes Security Act Now Before It’s Too Late
Kubernetes Security Act Now Before It’s Too LateKubernetes Security Act Now Before It’s Too Late
Kubernetes Security Act Now Before It’s Too Late
Michael Furman
 
Integration of Utility Data into 3D BIM Models Using a 3D Solids Modeling Wor...
Integration of Utility Data into 3D BIM Models Using a 3D Solids Modeling Wor...Integration of Utility Data into 3D BIM Models Using a 3D Solids Modeling Wor...
Integration of Utility Data into 3D BIM Models Using a 3D Solids Modeling Wor...
Safe Software
 
Artificial Intelligence in the Nonprofit Boardroom.pdf
Artificial Intelligence in the Nonprofit Boardroom.pdfArtificial Intelligence in the Nonprofit Boardroom.pdf
Artificial Intelligence in the Nonprofit Boardroom.pdf
OnBoard
 
Can We Use Rust to Develop Extensions for PostgreSQL? (POSETTE: An Event for ...
Can We Use Rust to Develop Extensions for PostgreSQL? (POSETTE: An Event for ...Can We Use Rust to Develop Extensions for PostgreSQL? (POSETTE: An Event for ...
Can We Use Rust to Develop Extensions for PostgreSQL? (POSETTE: An Event for ...
NTT DATA Technology & Innovation
 
Agentic AI: Beyond the Buzz- LangGraph Studio V2
Agentic AI: Beyond the Buzz- LangGraph Studio V2Agentic AI: Beyond the Buzz- LangGraph Studio V2
Agentic AI: Beyond the Buzz- LangGraph Studio V2
Shashikant Jagtap
 
Oracle Cloud Infrastructure AI Foundations
Oracle Cloud Infrastructure AI FoundationsOracle Cloud Infrastructure AI Foundations
Oracle Cloud Infrastructure AI Foundations
VICTOR MAESTRE RAMIREZ
 
Oracle Cloud and AI Specialization Program
Oracle Cloud and AI Specialization ProgramOracle Cloud and AI Specialization Program
Oracle Cloud and AI Specialization Program
VICTOR MAESTRE RAMIREZ
 
Precisely Demo Showcase: Powering ServiceNow Discovery with Precisely Ironstr...
Precisely Demo Showcase: Powering ServiceNow Discovery with Precisely Ironstr...Precisely Demo Showcase: Powering ServiceNow Discovery with Precisely Ironstr...
Precisely Demo Showcase: Powering ServiceNow Discovery with Precisely Ironstr...
Precisely
 
If You Use Databricks, You Definitely Need FME
If You Use Databricks, You Definitely Need FMEIf You Use Databricks, You Definitely Need FME
If You Use Databricks, You Definitely Need FME
Safe Software
 
Providing an OGC API Processes REST Interface for FME Flow
Providing an OGC API Processes REST Interface for FME FlowProviding an OGC API Processes REST Interface for FME Flow
Providing an OGC API Processes REST Interface for FME Flow
Safe Software
 
Your startup on AWS - How to architect and maintain a Lean and Mean account J...
Your startup on AWS - How to architect and maintain a Lean and Mean account J...Your startup on AWS - How to architect and maintain a Lean and Mean account J...
Your startup on AWS - How to architect and maintain a Lean and Mean account J...
angelo60207
 
Scaling GenAI Inference From Prototype to Production: Real-World Lessons in S...
Scaling GenAI Inference From Prototype to Production: Real-World Lessons in S...Scaling GenAI Inference From Prototype to Production: Real-World Lessons in S...
Scaling GenAI Inference From Prototype to Production: Real-World Lessons in S...
Anish Kumar
 
Ad

Connect to NoSQL Database (MongoDB) using Node JS & Connect Node.js with NoSQL MongoDB Database

  • 1. Connect to NoSQL Database using Node JS
  • 2. What Is a Database •A database is an organized collection of structured information, or data, typically stored electronically in a computer system
  • 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.
  • 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.
  • 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.
  • 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
  • 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.
  • 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.
  • 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).
  • 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.
  • 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
  • 13. Simple JSON Data { "name": "Alex C", "age": 22, "city": “Erode" }
  • 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
  • 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" }
  • 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
  • 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).
  • 19. Fields (key and value pairs) are stored in document, documents are stored in collection and collections are stored in database.
  • 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.
  • 22. Download MongoDB •download MongoDB from the official website: https://www.mongodb.com/download-center/communi ty . • 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
  • 27. Step 1 : Check properly installed or not Open cmd and type: •mongod -version •mongo -version
  • 28. Step 2 : Server on & Client on Open two separate cmd and type: One for server & another for client • mongod • mongo
  • 29. Within Mongo (Client) window Shows databases show dbs Ans: admin 0.000GB config 0.000GB local 0.000GB
  • 32. Insert data db.posts.insertOne({name:"abi"}) Ans: { "acknowledged" : true, "insertedId" : ObjectId("643e391ee1f9ddc511f3beaf") }
  • 33. View / Select /find a data db.posts.find() Ans: { "_id" : ObjectId("643e391ee1f9ddc511f3beaf"), "name" : "abi" }
  • 35. Delete command db.posts.deleteOne({ name: "helloword" }) Ans: { "acknowledged" : true, "deletedCount" : 1 }
  • 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.
  • 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');
  • 38. Mongoose Module Introduction •It provides several functions in order to manipulate the documents of the collection of the MongoDB database
  • 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.
  • 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.
  • 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)
  • 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
  • 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()
  • 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()
  • 45. Delete query const deletedata=async() => { await Name.deleteMany({name: 'Zildjian'}); } deletedata()
  • 46. Reference • https://masteringjs.io/mongoose • https://www.mongodb.com/docs/manual/tutorial/install-mongodb-o n-windows/ • https://mongoosejs.com/docs/5.x/docs/tutorials/findoneandupdate. html • https://www.youtube.com/watch?v=gB6WLkSrtJk