SlideShare a Scribd company logo
basics
JERWIN ROY J
Database Adminstrator
meetjerwin@gmail.com
Agenda
★ Introduction
★ MongoDB Installation
-yum
-binary
★ Roles in MongoDb
★ User creation
★ Basic commands
★ Trace Slow queries
★ Important monitoring commands
Introduction
What is NoSQL database?
A NoSQL or Not Only SQL database provides a mechanism
for storage and retrieval of data other than the tabular relations used
in relational databases. Motivations for this approach include simplicity of
design, horizontal scaling and finer control over availability.
What is mongodb?
MongoDB is a cross-platform, document oriented database
that provides, high performance, high availability, and easy scalability.
MongoDB works on concept of collection and document. It is also one of the
leading NoSQL database.
Why should we use MongoDB?
➔ Document Oriented Storage : Data is stored in the form of JSON style
documents
➔ Index on any attribute
➔ Replication & High Availability
➔ Auto-Sharding
➔ Rich Queries
➔ Fast In-Place Updates
➔ Map Reduce functions
➔ Professional Support By MongoDB
Database
Database is a physical container for collections. Each database gets its own set of
files on the file system. A single MongoDB server typically has multiple databases.
Collection
Collection is a group of MongoDB documents. It is the equivalent of an RDBMS table.
A collection exists within a single database. Collections do not enforce a schema.
Documents within a collection can have different fields. Typically, all documents in a
collection are of similar or related purpose.
Document
A document is a set of key-value pairs. Documents have dynamic schema. Dynamic
schema means that documents in the same collection do not need to have the same
set of fields or structure, and common fields in a collection's documents may
hold different types of data.
Relationship of RDBMS terminology with MongoDB
Installation - yum
1.Create a repo file as below:
vim /etc/yum.repos.d/mongodb.repo
2.For 64-bit systems type the below information in repo file and save.
[mongodb-org-3.0]
name=MongoDB 3.0 Repository
baseurl=http://downloads-distro.mongodb.org/repo/redhat/os/x86_64/
gpgcheck=0
enabled=1
3.To install all the packages of mongodb issue the below command:
yum install mongodb-org
4.Start the installed mongodb server using the below command:
service mongod start
5.The server is now started and to login to the mongo shell issue the below command:
mongo
No need to include the port because we are running it on the default port(27017).
6.To check the current status of mongod issue the below command:
service mongod status
7.To stop the running mongod server use the below command:
service mongod stop
8.To change the data directory with a new one,stop the current running instance and go
to the config file(/etc/mongod.conf) make the changes then save.
9.Now start the mongodb,it works with the new data directory.Make sure that the data
directory has mongod user permission.
1.The mongodb binary are found in the official page(https://www.mongodb.org/downloads).
2.Download the binary using wget
wget https://fastdl.mongodb.org/linux/mongodb-linux-x86_64-3.0.4.tgz
3.Now extract the downloaded file using the below command:
tar zxf mongodb-linux-x86_64-3.0.3.tgz
4.Now rename the extracted(mongodb-linux-x86 64-2.6.3) file into mongodb
mv mongodb-linux-x86 64-2.6.3 mongodb
Installation - binary
5.Create a data directory using the below command
mkdir -p /home/data/db
6: Create an user mongo user using the following command
useradd mongod
7.Change the ownership of the files in the source and data directory using the following
command
chown -R mongod.mongod /home/data/new
chown -R mongod.mongod /home/data/db/
7.Create a configuration file in any directory say
vim /etc/mongod.conf
8.Now add the following details as shown below:
dbpath = /home/data/db
logpath = /home/data/mongodb.log
logappend = true
port = 27017
auth = true
9.Open the script file /etc/init.d/mongod
vim /etc/init.d/mongod
10.Make the change path in the CONFIGFILE="/etc/mongod.conf" with your config file
path.
11.Start the mongodb server using the below command:
service mongod start
5.The server is now started and to login to the mongo shell issue the below command:
mongo
6.To check the current status of mongod issue the below command:
service mongod status
7.To stop the running mongod server use the below command:
service mongod stop
Roles in MongoDB
Super roles:
readAnyDatabase-reads any database
readWriteAnyDatabase-reads & writes any database
userAdminAnyDatabase-user admin role to any database
dbAdminAnyDatabase-database admin any database
DB user roles:
read-reads current database
readWrite-reads & writes current databadse
dbAdmin-access to system. collections in current db
userAdmin-create,modify roles & users in current db
dbOwner-readWrite, dbAdmin & userAdmin
Cluster roles:
hostManager-monitor,manage,kill & repair db
clusterMonitor-read only access to monitoring tools
clusterManager-all operations to manage db except drop
clusterAdmin- can drop & combo of clusterManager, clusterMonitor, & hostManager.
Backup roles:
backup-to take bakup
restore-to restore the backup files
Creating a user
Root user:
Provides access to the operations readWriteAnyDatabase,
dbAdminAnyDatabase, userAdminAnyDatabase and clusterAdmin roles combined. It does
not include any access to collections that begin with the system. prefix.Create admin users
in the admin database so that they can access all dbs.
use admin
db.createUser( { user: “root",
pwd: “rootabc",
roles: [“root” ]
} )
So after creating the user it is possible to login only with user beacuse we have enabled
auth.
super user:
use admin
db.createUser( { user: "superuser",
pwd: "admin",
roles: [ "userAdminAnyDatabase",
"dbAdminAnyDatabase",
"readWriteAnyDatabase"
] } )
Read user for a database:
use database
db.createUser(
{
user: "read",
pwd: "password",
roles:
[ {
role: "read",
db: "database"
}
]
}
)
monitoring user:
For the monitoring this user serves best:
db.createUser(
{
user: "monitoring",
pwd: "abc123",
roles: [ "clusterMonitor" ]
}
)
Verify the privilege using:
db.runCommand(
{
usersInfo:"admin",
showPrivileges:true
}
)
Kill a query:
Find the opid using currentop(_) command.
db.killOp(opid)
opid-it is the operation id of a particular query.
Basic commands
A few basic commands that are used in the mongodb client
are listed below:
use new_db -Uses the databasespecified
db -Displays the current database name
show dbs -Displays list of all databases
show collections -Displays list of all collections
db.dropDatabase() -Drops the current database in use
db.collection.drop() -Drops the collection mentioned
Trace Slow queries
Slow queries can be traced using database profiler.Mongodb has
three levels of profiling,each with unique feature.
db.setProfilingLevel(0) ->no profiling
db.setProfilingLevel(1) ->slow queries
db.setProfilingLevel(2) ->all queries
To check the current profiling level use the below command:
db.getProfilingStatus()
All the traced slow queries will be present in predefined collection
system.profile in the local database.To view the queries fire the below
command:
db.system.profile.find()
Important Monitoring commands
Serverstatus - Similar to mysql show processlist
db.serverStatus().uptime
db.serverStatus().connections
db.serverStatus().opcounters
currentop():
Display all the documents that contains information on in-progress operations for the database
instance
To view the current active queries in the database:
db.currentOp(
{
"active" : true
}
)
To view all active read queries:
db.currentOp().inprog.forEach(
function(d){
if(d.active && d.lockType == "read")
printjson(d)
})
To view all active write queries:
db.currentOp().inprog.forEach(
function(d){
if(d.waitingForLock && d.lockType != "write")
printjson(d)
})
To view the queries that are waiting for a lock and not a read:
db.currentOp().inprog.forEach(
function(d){
if(d.waitingForLock && d.lockType != "read")
printjson(d)
})
To view the queries that are running more than ‘x(2)’ seconds in the database:
db.currentOp(
{
"active" : true,
"secs_running" : { "$gt" : 2}
}
)
db.stats()- Statistics about a database
db.collection.stats():
Statistics about a particular collection
rs.status(): Statistics about a replica set
rs.printReplicationInfo()- Replication info such as sync between the replica
rs.printSlaveReplicationInfo()- Slave replication details
db.isMaster() - To check whether a replica is master,true returns its a master
Thank You
Ad

Recommended

Mongo db
Mongo db
Raghu nath
 
Introduction to mongo db
Introduction to mongo db
NexThoughts Technologies
 
Mongo db basics
Mongo db basics
Harischandra M K
 
Mongo db basics
Mongo db basics
Claudio Montoya
 
MongoDB for Beginners
MongoDB for Beginners
Enoch Joshua
 
Connecting NodeJS & MongoDB
Connecting NodeJS & MongoDB
Enoch Joshua
 
Get expertise with mongo db
Get expertise with mongo db
Amit Thakkar
 
Mongo DB: Fundamentals & Basics/ An Overview of MongoDB/ Mongo DB tutorials
Mongo DB: Fundamentals & Basics/ An Overview of MongoDB/ Mongo DB tutorials
SpringPeople
 
Mongo db
Mongo db
Swecha | స్వేచ్ఛ
 
Mongo DB 102
Mongo DB 102
Abhijeet Vaikar
 
Basics of MongoDB
Basics of MongoDB
HabileLabs
 
MongoDB 101
MongoDB 101
Abhijeet Vaikar
 
The Basics of MongoDB
The Basics of MongoDB
valuebound
 
MongoDB presentation
MongoDB presentation
Hyphen Call
 
Mongo DB
Mongo DB
Tata Consultancy Services
 
Top 10 frameworks of node js
Top 10 frameworks of node js
HabileLabs
 
Mongodb introduction and_internal(simple)
Mongodb introduction and_internal(simple)
Kai Zhao
 
MongoDB
MongoDB
nikhil2807
 
Mongo db dhruba
Mongo db dhruba
Dhrubaji Mandal ♛
 
Introduction to MongoDB
Introduction to MongoDB
Mike Dirolf
 
Mongo db
Mongo db
Noman Ellahi
 
Mongo db report
Mongo db report
Hyphen Call
 
An introduction to MongoDB
An introduction to MongoDB
César Trigo
 
Mongo db1
Mongo db1
VandanaKukreja
 
Mongodb
Mongodb
Scott Motte
 
Introduction to MongoDB
Introduction to MongoDB
Ravi Teja
 
Introduction to mongo db
Introduction to mongo db
Rohit Bishnoi
 
Introduction to mongodb
Introduction to mongodb
neela madheswari
 
Training MongoDB - Monitoring and Operability
Training MongoDB - Monitoring and Operability
Nicolas Motte
 
Webinar slides: Become a MongoDB DBA - What to Monitor (if you’re really a My...
Webinar slides: Become a MongoDB DBA - What to Monitor (if you’re really a My...
Severalnines
 

More Related Content

What's hot (20)

Mongo db
Mongo db
Swecha | స్వేచ్ఛ
 
Mongo DB 102
Mongo DB 102
Abhijeet Vaikar
 
Basics of MongoDB
Basics of MongoDB
HabileLabs
 
MongoDB 101
MongoDB 101
Abhijeet Vaikar
 
The Basics of MongoDB
The Basics of MongoDB
valuebound
 
MongoDB presentation
MongoDB presentation
Hyphen Call
 
Mongo DB
Mongo DB
Tata Consultancy Services
 
Top 10 frameworks of node js
Top 10 frameworks of node js
HabileLabs
 
Mongodb introduction and_internal(simple)
Mongodb introduction and_internal(simple)
Kai Zhao
 
MongoDB
MongoDB
nikhil2807
 
Mongo db dhruba
Mongo db dhruba
Dhrubaji Mandal ♛
 
Introduction to MongoDB
Introduction to MongoDB
Mike Dirolf
 
Mongo db
Mongo db
Noman Ellahi
 
Mongo db report
Mongo db report
Hyphen Call
 
An introduction to MongoDB
An introduction to MongoDB
César Trigo
 
Mongo db1
Mongo db1
VandanaKukreja
 
Mongodb
Mongodb
Scott Motte
 
Introduction to MongoDB
Introduction to MongoDB
Ravi Teja
 
Introduction to mongo db
Introduction to mongo db
Rohit Bishnoi
 
Introduction to mongodb
Introduction to mongodb
neela madheswari
 

Viewers also liked (20)

Training MongoDB - Monitoring and Operability
Training MongoDB - Monitoring and Operability
Nicolas Motte
 
Webinar slides: Become a MongoDB DBA - What to Monitor (if you’re really a My...
Webinar slides: Become a MongoDB DBA - What to Monitor (if you’re really a My...
Severalnines
 
MongoDB training for java software engineers
MongoDB training for java software engineers
Moshe Kaplan
 
Server discovery and monitoring with MongoDB
Server discovery and monitoring with MongoDB
Joe Drumgoole
 
Secrets of World Class HR Depts | webinar with PayStream Advisors & docSTAR
Secrets of World Class HR Depts | webinar with PayStream Advisors & docSTAR
docSTAR
 
iMIS 20 Overview for Education Associations
iMIS 20 Overview for Education Associations
iMIS
 
Oa presentation1 (1)
Oa presentation1 (1)
Gamut Infosystems Ltd
 
HR Software, Payroll & Time Management: Discover Carval in 60 Seconds
HR Software, Payroll & Time Management: Discover Carval in 60 Seconds
Carval Computing Limited
 
medez web pesentation 1122015
medez web pesentation 1122015
MedEZ, Integrated Software Solutions
 
Production management software_to_the_rescue
Production management software_to_the_rescue
Argos Software
 
Is mobile's big promise a farce?
Is mobile's big promise a farce?
Mobile Roadie
 
SkillPoint™ VRx Recruiting Software
SkillPoint™ VRx Recruiting Software
Platina Software Pvt. Ltd.
 
Get a 3D view of your workforce
Get a 3D view of your workforce
Access Group
 
Documentation of technology practices using blog: case study of koha geek and...
Documentation of technology practices using blog: case study of koha geek and...
Mahatma Gandhi University Library
 
Marketing To Asian Women Conference Singapore
Marketing To Asian Women Conference Singapore
One9Ninety
 
Cloud Computing - What is it?
Cloud Computing - What is it?
Liquid Accounts
 
Why Are More Australians Shopping Small Business?
Why Are More Australians Shopping Small Business?
Cashflow Manager
 
How to use GitHub to Predict the Success of your Application
How to use GitHub to Predict the Success of your Application
Grip QA
 
4 habilidades de un líder
4 habilidades de un líder
Safi
 
Training MongoDB - Monitoring and Operability
Training MongoDB - Monitoring and Operability
Nicolas Motte
 
Webinar slides: Become a MongoDB DBA - What to Monitor (if you’re really a My...
Webinar slides: Become a MongoDB DBA - What to Monitor (if you’re really a My...
Severalnines
 
MongoDB training for java software engineers
MongoDB training for java software engineers
Moshe Kaplan
 
Server discovery and monitoring with MongoDB
Server discovery and monitoring with MongoDB
Joe Drumgoole
 
Secrets of World Class HR Depts | webinar with PayStream Advisors & docSTAR
Secrets of World Class HR Depts | webinar with PayStream Advisors & docSTAR
docSTAR
 
iMIS 20 Overview for Education Associations
iMIS 20 Overview for Education Associations
iMIS
 
HR Software, Payroll & Time Management: Discover Carval in 60 Seconds
HR Software, Payroll & Time Management: Discover Carval in 60 Seconds
Carval Computing Limited
 
Production management software_to_the_rescue
Production management software_to_the_rescue
Argos Software
 
Is mobile's big promise a farce?
Is mobile's big promise a farce?
Mobile Roadie
 
Get a 3D view of your workforce
Get a 3D view of your workforce
Access Group
 
Documentation of technology practices using blog: case study of koha geek and...
Documentation of technology practices using blog: case study of koha geek and...
Mahatma Gandhi University Library
 
Marketing To Asian Women Conference Singapore
Marketing To Asian Women Conference Singapore
One9Ninety
 
Cloud Computing - What is it?
Cloud Computing - What is it?
Liquid Accounts
 
Why Are More Australians Shopping Small Business?
Why Are More Australians Shopping Small Business?
Cashflow Manager
 
How to use GitHub to Predict the Success of your Application
How to use GitHub to Predict the Success of your Application
Grip QA
 
4 habilidades de un líder
4 habilidades de un líder
Safi
 
Ad

Similar to MongoDB basics & Introduction (20)

MongoDB - An Introduction
MongoDB - An Introduction
sethfloydjr
 
Introduction to MongoDB.pptx
Introduction to MongoDB.pptx
Surya937648
 
Quick & Dirty & MEAN
Quick & Dirty & MEAN
Troy Miles
 
Kalp Corporate MongoDB Tutorials
Kalp Corporate MongoDB Tutorials
Kalp Corporate
 
MongoDbPpt based on python installation.
MongoDbPpt based on python installation.
jnvcomputerlab2024
 
MongoDB
MongoDB
wiTTyMinds1
 
Mongo db Quick Guide
Mongo db Quick Guide
Sourabh Sahu
 
Mongodb
Mongodb
ichangbai
 
MongoDB introduction features -presentation - 2.pptx
MongoDB introduction features -presentation - 2.pptx
sampathkumar546444
 
MongoDB: Advantages of an Open Source NoSQL Database
MongoDB: Advantages of an Open Source NoSQL Database
FITC
 
Philadelphia MongoDB User Group - Your First MongoDB Application
Philadelphia MongoDB User Group - Your First MongoDB Application
Michael Lynn
 
Mongodb By Vipin
Mongodb By Vipin
Vipin Mundayad
 
Introduction to MongoDB a brief intro(1).pptx
Introduction to MongoDB a brief intro(1).pptx
mehfooz968268
 
Mongo db
Mongo db
Gyanendra Yadav
 
SQL vs NoSQL, an experiment with MongoDB
SQL vs NoSQL, an experiment with MongoDB
Marco Segato
 
The Little MongoDB Book - Karl Seguin
The Little MongoDB Book - Karl Seguin
Paulo Fagundes
 
Introduction to mongo db
Introduction to mongo db
Lawrence Mwai
 
Mongo db halloween party
Mongo db halloween party
Andrea Balducci
 
Mongodb
Mongodb
Paulo Fagundes
 
MongoDB.pdf54teeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeer
MongoDB.pdf54teeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeer
MdRiyad22
 
MongoDB - An Introduction
MongoDB - An Introduction
sethfloydjr
 
Introduction to MongoDB.pptx
Introduction to MongoDB.pptx
Surya937648
 
Quick & Dirty & MEAN
Quick & Dirty & MEAN
Troy Miles
 
Kalp Corporate MongoDB Tutorials
Kalp Corporate MongoDB Tutorials
Kalp Corporate
 
MongoDbPpt based on python installation.
MongoDbPpt based on python installation.
jnvcomputerlab2024
 
Mongo db Quick Guide
Mongo db Quick Guide
Sourabh Sahu
 
MongoDB introduction features -presentation - 2.pptx
MongoDB introduction features -presentation - 2.pptx
sampathkumar546444
 
MongoDB: Advantages of an Open Source NoSQL Database
MongoDB: Advantages of an Open Source NoSQL Database
FITC
 
Philadelphia MongoDB User Group - Your First MongoDB Application
Philadelphia MongoDB User Group - Your First MongoDB Application
Michael Lynn
 
Introduction to MongoDB a brief intro(1).pptx
Introduction to MongoDB a brief intro(1).pptx
mehfooz968268
 
SQL vs NoSQL, an experiment with MongoDB
SQL vs NoSQL, an experiment with MongoDB
Marco Segato
 
The Little MongoDB Book - Karl Seguin
The Little MongoDB Book - Karl Seguin
Paulo Fagundes
 
Introduction to mongo db
Introduction to mongo db
Lawrence Mwai
 
Mongo db halloween party
Mongo db halloween party
Andrea Balducci
 
MongoDB.pdf54teeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeer
MongoDB.pdf54teeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeer
MdRiyad22
 
Ad

Recently uploaded (20)

FIDO Seminar: Evolving Landscape of Post-Quantum Cryptography.pptx
FIDO Seminar: Evolving Landscape of Post-Quantum Cryptography.pptx
FIDO Alliance
 
Smarter Aviation Data Management: Lessons from Swedavia Airports and Sweco
Smarter Aviation Data Management: Lessons from Swedavia Airports and Sweco
Safe Software
 
"How to survive Black Friday: preparing e-commerce for a peak season", Yurii ...
"How to survive Black Friday: preparing e-commerce for a peak season", Yurii ...
Fwdays
 
Tech-ASan: Two-stage check for Address Sanitizer - Yixuan Cao.pdf
Tech-ASan: Two-stage check for Address Sanitizer - Yixuan Cao.pdf
caoyixuan2019
 
FIDO Seminar: Targeting Trust: The Future of Identity in the Workforce.pptx
FIDO Seminar: Targeting Trust: The Future of Identity in the Workforce.pptx
FIDO Alliance
 
Information Security Response Team Nepal_npCERT_Vice_President_Sudan_Jha.pdf
Information Security Response Team Nepal_npCERT_Vice_President_Sudan_Jha.pdf
ICT Frame Magazine Pvt. Ltd.
 
Coordinated Disclosure for ML - What's Different and What's the Same.pdf
Coordinated Disclosure for ML - What's Different and What's the Same.pdf
Priyanka Aash
 
Lessons Learned from Developing Secure AI Workflows.pdf
Lessons Learned from Developing Secure AI Workflows.pdf
Priyanka Aash
 
You are not excused! How to avoid security blind spots on the way to production
You are not excused! How to avoid security blind spots on the way to production
Michele Leroux Bustamante
 
MuleSoft for AgentForce : Topic Center and API Catalog
MuleSoft for AgentForce : Topic Center and API Catalog
shyamraj55
 
Securing AI - There Is No Try, Only Do!.pdf
Securing AI - There Is No Try, Only Do!.pdf
Priyanka Aash
 
CapCut Pro Crack For PC Latest Version {Fully Unlocked} 2025
CapCut Pro Crack For PC Latest Version {Fully Unlocked} 2025
pcprocore
 
Raman Bhaumik - Passionate Tech Enthusiast
Raman Bhaumik - Passionate Tech Enthusiast
Raman Bhaumik
 
Improving Data Integrity: Synchronization between EAM and ArcGIS Utility Netw...
Improving Data Integrity: Synchronization between EAM and ArcGIS Utility Netw...
Safe Software
 
Cluster-Based Multi-Objective Metamorphic Test Case Pair Selection for Deep N...
Cluster-Based Multi-Objective Metamorphic Test Case Pair Selection for Deep N...
janeliewang985
 
Python Conference Singapore - 19 Jun 2025
Python Conference Singapore - 19 Jun 2025
ninefyi
 
AI VIDEO MAGAZINE - June 2025 - r/aivideo
AI VIDEO MAGAZINE - June 2025 - r/aivideo
1pcity Studios, Inc
 
FIDO Seminar: Authentication for a Billion Consumers - Amazon.pptx
FIDO Seminar: Authentication for a Billion Consumers - Amazon.pptx
FIDO Alliance
 
The Future of AI Agent Development Trends to Watch.pptx
The Future of AI Agent Development Trends to Watch.pptx
Lisa ward
 
OpenACC and Open Hackathons Monthly Highlights June 2025
OpenACC and Open Hackathons Monthly Highlights June 2025
OpenACC
 
FIDO Seminar: Evolving Landscape of Post-Quantum Cryptography.pptx
FIDO Seminar: Evolving Landscape of Post-Quantum Cryptography.pptx
FIDO Alliance
 
Smarter Aviation Data Management: Lessons from Swedavia Airports and Sweco
Smarter Aviation Data Management: Lessons from Swedavia Airports and Sweco
Safe Software
 
"How to survive Black Friday: preparing e-commerce for a peak season", Yurii ...
"How to survive Black Friday: preparing e-commerce for a peak season", Yurii ...
Fwdays
 
Tech-ASan: Two-stage check for Address Sanitizer - Yixuan Cao.pdf
Tech-ASan: Two-stage check for Address Sanitizer - Yixuan Cao.pdf
caoyixuan2019
 
FIDO Seminar: Targeting Trust: The Future of Identity in the Workforce.pptx
FIDO Seminar: Targeting Trust: The Future of Identity in the Workforce.pptx
FIDO Alliance
 
Information Security Response Team Nepal_npCERT_Vice_President_Sudan_Jha.pdf
Information Security Response Team Nepal_npCERT_Vice_President_Sudan_Jha.pdf
ICT Frame Magazine Pvt. Ltd.
 
Coordinated Disclosure for ML - What's Different and What's the Same.pdf
Coordinated Disclosure for ML - What's Different and What's the Same.pdf
Priyanka Aash
 
Lessons Learned from Developing Secure AI Workflows.pdf
Lessons Learned from Developing Secure AI Workflows.pdf
Priyanka Aash
 
You are not excused! How to avoid security blind spots on the way to production
You are not excused! How to avoid security blind spots on the way to production
Michele Leroux Bustamante
 
MuleSoft for AgentForce : Topic Center and API Catalog
MuleSoft for AgentForce : Topic Center and API Catalog
shyamraj55
 
Securing AI - There Is No Try, Only Do!.pdf
Securing AI - There Is No Try, Only Do!.pdf
Priyanka Aash
 
CapCut Pro Crack For PC Latest Version {Fully Unlocked} 2025
CapCut Pro Crack For PC Latest Version {Fully Unlocked} 2025
pcprocore
 
Raman Bhaumik - Passionate Tech Enthusiast
Raman Bhaumik - Passionate Tech Enthusiast
Raman Bhaumik
 
Improving Data Integrity: Synchronization between EAM and ArcGIS Utility Netw...
Improving Data Integrity: Synchronization between EAM and ArcGIS Utility Netw...
Safe Software
 
Cluster-Based Multi-Objective Metamorphic Test Case Pair Selection for Deep N...
Cluster-Based Multi-Objective Metamorphic Test Case Pair Selection for Deep N...
janeliewang985
 
Python Conference Singapore - 19 Jun 2025
Python Conference Singapore - 19 Jun 2025
ninefyi
 
AI VIDEO MAGAZINE - June 2025 - r/aivideo
AI VIDEO MAGAZINE - June 2025 - r/aivideo
1pcity Studios, Inc
 
FIDO Seminar: Authentication for a Billion Consumers - Amazon.pptx
FIDO Seminar: Authentication for a Billion Consumers - Amazon.pptx
FIDO Alliance
 
The Future of AI Agent Development Trends to Watch.pptx
The Future of AI Agent Development Trends to Watch.pptx
Lisa ward
 
OpenACC and Open Hackathons Monthly Highlights June 2025
OpenACC and Open Hackathons Monthly Highlights June 2025
OpenACC
 

MongoDB basics & Introduction

  • 2. Agenda ★ Introduction ★ MongoDB Installation -yum -binary ★ Roles in MongoDb ★ User creation ★ Basic commands ★ Trace Slow queries ★ Important monitoring commands
  • 3. Introduction What is NoSQL database? A NoSQL or Not Only SQL database provides a mechanism for storage and retrieval of data other than the tabular relations used in relational databases. Motivations for this approach include simplicity of design, horizontal scaling and finer control over availability. What is mongodb? MongoDB is a cross-platform, document oriented database that provides, high performance, high availability, and easy scalability. MongoDB works on concept of collection and document. It is also one of the leading NoSQL database.
  • 4. Why should we use MongoDB? ➔ Document Oriented Storage : Data is stored in the form of JSON style documents ➔ Index on any attribute ➔ Replication & High Availability ➔ Auto-Sharding ➔ Rich Queries ➔ Fast In-Place Updates ➔ Map Reduce functions ➔ Professional Support By MongoDB
  • 5. Database Database is a physical container for collections. Each database gets its own set of files on the file system. A single MongoDB server typically has multiple databases. Collection Collection is a group of MongoDB documents. It is the equivalent of an RDBMS table. A collection exists within a single database. Collections do not enforce a schema. Documents within a collection can have different fields. Typically, all documents in a collection are of similar or related purpose. Document A document is a set of key-value pairs. Documents have dynamic schema. Dynamic schema means that documents in the same collection do not need to have the same set of fields or structure, and common fields in a collection's documents may hold different types of data.
  • 6. Relationship of RDBMS terminology with MongoDB
  • 7. Installation - yum 1.Create a repo file as below: vim /etc/yum.repos.d/mongodb.repo 2.For 64-bit systems type the below information in repo file and save. [mongodb-org-3.0] name=MongoDB 3.0 Repository baseurl=http://downloads-distro.mongodb.org/repo/redhat/os/x86_64/ gpgcheck=0 enabled=1
  • 8. 3.To install all the packages of mongodb issue the below command: yum install mongodb-org 4.Start the installed mongodb server using the below command: service mongod start 5.The server is now started and to login to the mongo shell issue the below command: mongo No need to include the port because we are running it on the default port(27017).
  • 9. 6.To check the current status of mongod issue the below command: service mongod status 7.To stop the running mongod server use the below command: service mongod stop 8.To change the data directory with a new one,stop the current running instance and go to the config file(/etc/mongod.conf) make the changes then save. 9.Now start the mongodb,it works with the new data directory.Make sure that the data directory has mongod user permission.
  • 10. 1.The mongodb binary are found in the official page(https://www.mongodb.org/downloads). 2.Download the binary using wget wget https://fastdl.mongodb.org/linux/mongodb-linux-x86_64-3.0.4.tgz 3.Now extract the downloaded file using the below command: tar zxf mongodb-linux-x86_64-3.0.3.tgz 4.Now rename the extracted(mongodb-linux-x86 64-2.6.3) file into mongodb mv mongodb-linux-x86 64-2.6.3 mongodb Installation - binary
  • 11. 5.Create a data directory using the below command mkdir -p /home/data/db 6: Create an user mongo user using the following command useradd mongod 7.Change the ownership of the files in the source and data directory using the following command chown -R mongod.mongod /home/data/new chown -R mongod.mongod /home/data/db/
  • 12. 7.Create a configuration file in any directory say vim /etc/mongod.conf 8.Now add the following details as shown below: dbpath = /home/data/db logpath = /home/data/mongodb.log logappend = true port = 27017 auth = true
  • 13. 9.Open the script file /etc/init.d/mongod vim /etc/init.d/mongod 10.Make the change path in the CONFIGFILE="/etc/mongod.conf" with your config file path. 11.Start the mongodb server using the below command: service mongod start
  • 14. 5.The server is now started and to login to the mongo shell issue the below command: mongo 6.To check the current status of mongod issue the below command: service mongod status 7.To stop the running mongod server use the below command: service mongod stop
  • 15. Roles in MongoDB Super roles: readAnyDatabase-reads any database readWriteAnyDatabase-reads & writes any database userAdminAnyDatabase-user admin role to any database dbAdminAnyDatabase-database admin any database DB user roles: read-reads current database readWrite-reads & writes current databadse dbAdmin-access to system. collections in current db userAdmin-create,modify roles & users in current db dbOwner-readWrite, dbAdmin & userAdmin
  • 16. Cluster roles: hostManager-monitor,manage,kill & repair db clusterMonitor-read only access to monitoring tools clusterManager-all operations to manage db except drop clusterAdmin- can drop & combo of clusterManager, clusterMonitor, & hostManager. Backup roles: backup-to take bakup restore-to restore the backup files
  • 17. Creating a user Root user: Provides access to the operations readWriteAnyDatabase, dbAdminAnyDatabase, userAdminAnyDatabase and clusterAdmin roles combined. It does not include any access to collections that begin with the system. prefix.Create admin users in the admin database so that they can access all dbs. use admin db.createUser( { user: “root", pwd: “rootabc", roles: [“root” ] } )
  • 18. So after creating the user it is possible to login only with user beacuse we have enabled auth. super user: use admin db.createUser( { user: "superuser", pwd: "admin", roles: [ "userAdminAnyDatabase", "dbAdminAnyDatabase", "readWriteAnyDatabase" ] } )
  • 19. Read user for a database: use database db.createUser( { user: "read", pwd: "password", roles: [ { role: "read", db: "database" } ] } )
  • 20. monitoring user: For the monitoring this user serves best: db.createUser( { user: "monitoring", pwd: "abc123", roles: [ "clusterMonitor" ] } )
  • 21. Verify the privilege using: db.runCommand( { usersInfo:"admin", showPrivileges:true } ) Kill a query: Find the opid using currentop(_) command. db.killOp(opid) opid-it is the operation id of a particular query.
  • 22. Basic commands A few basic commands that are used in the mongodb client are listed below: use new_db -Uses the databasespecified db -Displays the current database name show dbs -Displays list of all databases show collections -Displays list of all collections db.dropDatabase() -Drops the current database in use db.collection.drop() -Drops the collection mentioned
  • 23. Trace Slow queries Slow queries can be traced using database profiler.Mongodb has three levels of profiling,each with unique feature. db.setProfilingLevel(0) ->no profiling db.setProfilingLevel(1) ->slow queries db.setProfilingLevel(2) ->all queries To check the current profiling level use the below command: db.getProfilingStatus() All the traced slow queries will be present in predefined collection system.profile in the local database.To view the queries fire the below command: db.system.profile.find()
  • 24. Important Monitoring commands Serverstatus - Similar to mysql show processlist db.serverStatus().uptime db.serverStatus().connections db.serverStatus().opcounters
  • 25. currentop(): Display all the documents that contains information on in-progress operations for the database instance To view the current active queries in the database: db.currentOp( { "active" : true } ) To view all active read queries: db.currentOp().inprog.forEach( function(d){ if(d.active && d.lockType == "read") printjson(d) })
  • 26. To view all active write queries: db.currentOp().inprog.forEach( function(d){ if(d.waitingForLock && d.lockType != "write") printjson(d) }) To view the queries that are waiting for a lock and not a read: db.currentOp().inprog.forEach( function(d){ if(d.waitingForLock && d.lockType != "read") printjson(d) })
  • 27. To view the queries that are running more than ‘x(2)’ seconds in the database: db.currentOp( { "active" : true, "secs_running" : { "$gt" : 2} } )
  • 31. rs.printReplicationInfo()- Replication info such as sync between the replica rs.printSlaveReplicationInfo()- Slave replication details
  • 32. db.isMaster() - To check whether a replica is master,true returns its a master