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

More Related Content

What's hot

Mongo DB 102
Mongo DB 102Mongo DB 102
Mongo DB 102
Abhijeet Vaikar
 
Basics of MongoDB
Basics of MongoDB Basics of MongoDB
Basics of MongoDB
Habilelabs
 
MongoDB 101
MongoDB 101MongoDB 101
MongoDB 101
Abhijeet Vaikar
 
The Basics of MongoDB
The Basics of MongoDBThe Basics of MongoDB
The Basics of MongoDB
valuebound
 
MongoDB presentation
MongoDB presentationMongoDB presentation
MongoDB presentation
Hyphen Call
 
Mongo DB
Mongo DB Mongo DB
Top 10 frameworks of node js
Top 10 frameworks of node jsTop 10 frameworks of node js
Top 10 frameworks of node js
Habilelabs
 
Mongodb introduction and_internal(simple)
Mongodb introduction and_internal(simple)Mongodb introduction and_internal(simple)
Mongodb introduction and_internal(simple)Kai Zhao
 
Mongo db dhruba
Mongo db dhrubaMongo db dhruba
Mongo db dhruba
Dhrubaji Mandal ♛
 
Introduction to MongoDB
Introduction to MongoDBIntroduction to MongoDB
Introduction to MongoDB
Mike Dirolf
 
Mongo db
Mongo dbMongo db
Mongo db
Noman Ellahi
 
Mongo db report
Mongo db reportMongo db report
Mongo db report
Hyphen Call
 
An introduction to MongoDB
An introduction to MongoDBAn introduction to MongoDB
An introduction to MongoDB
César Trigo
 
Mongo db1
Mongo db1Mongo db1
Mongo db1
VandanaKukreja
 
Mongodb
MongodbMongodb
Mongodb
Scott Motte
 
Introduction to MongoDB
Introduction to MongoDBIntroduction to MongoDB
Introduction to MongoDB
Ravi Teja
 
Introduction to mongo db
Introduction to mongo dbIntroduction to mongo db
Introduction to mongo db
Rohit Bishnoi
 
Introduction to mongodb
Introduction to mongodbIntroduction to mongodb
Introduction to mongodb
neela madheswari
 

What's hot (20)

Mongo db
Mongo dbMongo db
Mongo db
 
Mongo DB 102
Mongo DB 102Mongo DB 102
Mongo DB 102
 
Basics of MongoDB
Basics of MongoDB Basics of MongoDB
Basics of MongoDB
 
MongoDB 101
MongoDB 101MongoDB 101
MongoDB 101
 
The Basics of MongoDB
The Basics of MongoDBThe Basics of MongoDB
The Basics of MongoDB
 
MongoDB presentation
MongoDB presentationMongoDB presentation
MongoDB presentation
 
Mongo DB
Mongo DB Mongo DB
Mongo DB
 
Top 10 frameworks of node js
Top 10 frameworks of node jsTop 10 frameworks of node js
Top 10 frameworks of node js
 
Mongodb introduction and_internal(simple)
Mongodb introduction and_internal(simple)Mongodb introduction and_internal(simple)
Mongodb introduction and_internal(simple)
 
MongoDB
MongoDBMongoDB
MongoDB
 
Mongo db dhruba
Mongo db dhrubaMongo db dhruba
Mongo db dhruba
 
Introduction to MongoDB
Introduction to MongoDBIntroduction to MongoDB
Introduction to MongoDB
 
Mongo db
Mongo dbMongo db
Mongo db
 
Mongo db report
Mongo db reportMongo db report
Mongo db report
 
An introduction to MongoDB
An introduction to MongoDBAn introduction to MongoDB
An introduction to MongoDB
 
Mongo db1
Mongo db1Mongo db1
Mongo db1
 
Mongodb
MongodbMongodb
Mongodb
 
Introduction to MongoDB
Introduction to MongoDBIntroduction to MongoDB
Introduction to MongoDB
 
Introduction to mongo db
Introduction to mongo dbIntroduction to mongo db
Introduction to mongo db
 
Introduction to mongodb
Introduction to mongodbIntroduction to mongodb
Introduction to mongodb
 

Viewers also liked

Training MongoDB - Monitoring and Operability
Training MongoDB - Monitoring and OperabilityTraining 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...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 engineersMongoDB training for java software engineers
MongoDB training for java software engineers
Moshe Kaplan
 
Server discovery and monitoring with MongoDB
Server discovery and monitoring with MongoDBServer 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 & docSTARSecrets 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 AssociationsiMIS 20 Overview for Education Associations
iMIS 20 Overview for Education Associations
iMIS
 
Oa presentation1 (1)
Oa presentation1 (1)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 SecondsHR 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_rescueProduction management software_to_the_rescue
Production management software_to_the_rescueArgos Software
 
Is mobile's big promise a farce?
Is mobile's big promise a farce?Is mobile's big promise a farce?
Is mobile's big promise a farce?
Mobile Roadie
 
SkillPoint™ VRx Recruiting Software
SkillPoint™ VRx Recruiting SoftwareSkillPoint™ VRx Recruiting Software
SkillPoint™ VRx Recruiting Software
Platina Software Pvt. Ltd.
 
Get a 3D view of your workforce
Get a 3D view of your workforceGet 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...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 SingaporeMarketing To Asian Women Conference Singapore
Marketing To Asian Women Conference Singapore
One9Ninety
 
Cloud Computing - What is it?
Cloud Computing - What is it?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?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 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íder4 habilidades de un líder
4 habilidades de un líder
Safi
 

Viewers also liked (20)

Training MongoDB - Monitoring and Operability
Training MongoDB - Monitoring and OperabilityTraining MongoDB - Monitoring and Operability
Training MongoDB - Monitoring and Operability
 
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...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...
 
MongoDB training for java software engineers
MongoDB training for java software engineersMongoDB training for java software engineers
MongoDB training for java software engineers
 
Server discovery and monitoring with MongoDB
Server discovery and monitoring with MongoDBServer discovery and monitoring with MongoDB
Server discovery and monitoring with MongoDB
 
Secrets of World Class HR Depts | webinar with PayStream Advisors & docSTAR
Secrets of World Class HR Depts | webinar with PayStream Advisors & docSTARSecrets of World Class HR Depts | webinar with PayStream Advisors & docSTAR
Secrets of World Class HR Depts | webinar with PayStream Advisors & docSTAR
 
iMIS 20 Overview for Education Associations
iMIS 20 Overview for Education AssociationsiMIS 20 Overview for Education Associations
iMIS 20 Overview for Education Associations
 
Feeling words
Feeling wordsFeeling words
Feeling words
 
Oa presentation1 (1)
Oa presentation1 (1)Oa presentation1 (1)
Oa presentation1 (1)
 
HR Software, Payroll & Time Management: Discover Carval in 60 Seconds
HR Software, Payroll & Time Management: Discover Carval in 60 SecondsHR Software, Payroll & Time Management: Discover Carval in 60 Seconds
HR Software, Payroll & Time Management: Discover Carval in 60 Seconds
 
medez web pesentation 1122015
medez web pesentation 1122015medez web pesentation 1122015
medez web pesentation 1122015
 
Production management software_to_the_rescue
Production management software_to_the_rescueProduction management software_to_the_rescue
Production management software_to_the_rescue
 
Is mobile's big promise a farce?
Is mobile's big promise a farce?Is mobile's big promise a farce?
Is mobile's big promise a farce?
 
SkillPoint™ VRx Recruiting Software
SkillPoint™ VRx Recruiting SoftwareSkillPoint™ VRx Recruiting Software
SkillPoint™ VRx Recruiting Software
 
Get a 3D view of your workforce
Get a 3D view of your workforceGet a 3D view of your workforce
Get a 3D view of your workforce
 
Documentation of technology practices using blog: case study of koha geek and...
Documentation of technology practices using blog: case study of koha geek and...Documentation of technology practices using blog: case study of koha geek and...
Documentation of technology practices using blog: case study of koha geek and...
 
Marketing To Asian Women Conference Singapore
Marketing To Asian Women Conference SingaporeMarketing To Asian Women Conference Singapore
Marketing To Asian Women Conference Singapore
 
Cloud Computing - What is it?
Cloud Computing - What is it?Cloud Computing - What is it?
Cloud Computing - What is it?
 
Why Are More Australians Shopping Small Business?
Why Are More Australians Shopping Small Business?Why Are More Australians Shopping Small Business?
Why Are More Australians Shopping Small Business?
 
How to use GitHub to Predict the Success of your Application
How to use GitHub to  Predict the Success of your Application How to use GitHub to  Predict the Success of your Application
How to use GitHub to Predict the Success of your Application
 
4 habilidades de un líder
4 habilidades de un líder4 habilidades de un líder
4 habilidades de un líder
 

Similar to MongoDB basics & Introduction

MongoDB
MongoDBMongoDB
MongoDB
wiTTyMinds1
 
MongoDB: Advantages of an Open Source NoSQL Database
MongoDB: Advantages of an Open Source NoSQL DatabaseMongoDB: Advantages of an Open Source NoSQL Database
MongoDB: Advantages of an Open Source NoSQL Database
FITC
 
Mongodb replication
Mongodb replicationMongodb replication
Mongodb replication
PoguttuezhiniVP
 
Mongodb By Vipin
Mongodb By VipinMongodb By Vipin
Mongodb By Vipin
Vipin Mundayad
 
Getting started with replica set in MongoDB
Getting started with replica set in MongoDBGetting started with replica set in MongoDB
Getting started with replica set in MongoDBKishor Parkhe
 
Install and configure mongo db nosql db on windows
Install and configure mongo db nosql db on windowsInstall and configure mongo db nosql db on windows
Install and configure mongo db nosql db on windows
prabakaranbrick
 
MongoDB and DynamoDB
MongoDB and DynamoDBMongoDB and DynamoDB
MongoDB and DynamoDB
Md. Minhazul Haque
 
Experiment no 1
Experiment no 1Experiment no 1
Experiment no 1
Ankit Dubey
 
Setting up mongo replica set
Setting up mongo replica setSetting up mongo replica set
Setting up mongo replica setSudheer Kondla
 
MongoDB Pros and Cons
MongoDB Pros and ConsMongoDB Pros and Cons
MongoDB Pros and Cons
johnrjenson
 
mongodb tutorial
mongodb tutorialmongodb tutorial
mongodb tutorial
Jaehong Park
 
Configuring MongoDB HA Replica Set on AWS EC2
Configuring MongoDB HA Replica Set on AWS EC2Configuring MongoDB HA Replica Set on AWS EC2
Configuring MongoDB HA Replica Set on AWS EC2
ShepHertz
 
Setting up mongodb sharded cluster in 30 minutes
Setting up mongodb sharded cluster in 30 minutesSetting up mongodb sharded cluster in 30 minutes
Setting up mongodb sharded cluster in 30 minutes
Sudheer Kondla
 
Mdb dn 2016_07_elastic_search
Mdb dn 2016_07_elastic_searchMdb dn 2016_07_elastic_search
Mdb dn 2016_07_elastic_search
Daniel M. Farrell
 
introtomongodb
introtomongodbintrotomongodb
introtomongodbsaikiran
 
How do i Meet MongoDB
How do i Meet MongoDBHow do i Meet MongoDB
How do i Meet MongoDB
Antonio Scalzo
 
Introduction to MongoDB.pptx
Introduction to MongoDB.pptxIntroduction to MongoDB.pptx
Introduction to MongoDB.pptx
Surya937648
 
The Care + Feeding of a Mongodb Cluster
The Care + Feeding of a Mongodb ClusterThe Care + Feeding of a Mongodb Cluster
The Care + Feeding of a Mongodb ClusterChris Henry
 
MongoDB - An Introduction
MongoDB - An IntroductionMongoDB - An Introduction
MongoDB - An Introduction
dinkar thakur
 
Pandora FMS: MongoDB plugin
Pandora FMS: MongoDB pluginPandora FMS: MongoDB plugin
Pandora FMS: MongoDB plugin
Pandora FMS
 

Similar to MongoDB basics & Introduction (20)

MongoDB
MongoDBMongoDB
MongoDB
 
MongoDB: Advantages of an Open Source NoSQL Database
MongoDB: Advantages of an Open Source NoSQL DatabaseMongoDB: Advantages of an Open Source NoSQL Database
MongoDB: Advantages of an Open Source NoSQL Database
 
Mongodb replication
Mongodb replicationMongodb replication
Mongodb replication
 
Mongodb By Vipin
Mongodb By VipinMongodb By Vipin
Mongodb By Vipin
 
Getting started with replica set in MongoDB
Getting started with replica set in MongoDBGetting started with replica set in MongoDB
Getting started with replica set in MongoDB
 
Install and configure mongo db nosql db on windows
Install and configure mongo db nosql db on windowsInstall and configure mongo db nosql db on windows
Install and configure mongo db nosql db on windows
 
MongoDB and DynamoDB
MongoDB and DynamoDBMongoDB and DynamoDB
MongoDB and DynamoDB
 
Experiment no 1
Experiment no 1Experiment no 1
Experiment no 1
 
Setting up mongo replica set
Setting up mongo replica setSetting up mongo replica set
Setting up mongo replica set
 
MongoDB Pros and Cons
MongoDB Pros and ConsMongoDB Pros and Cons
MongoDB Pros and Cons
 
mongodb tutorial
mongodb tutorialmongodb tutorial
mongodb tutorial
 
Configuring MongoDB HA Replica Set on AWS EC2
Configuring MongoDB HA Replica Set on AWS EC2Configuring MongoDB HA Replica Set on AWS EC2
Configuring MongoDB HA Replica Set on AWS EC2
 
Setting up mongodb sharded cluster in 30 minutes
Setting up mongodb sharded cluster in 30 minutesSetting up mongodb sharded cluster in 30 minutes
Setting up mongodb sharded cluster in 30 minutes
 
Mdb dn 2016_07_elastic_search
Mdb dn 2016_07_elastic_searchMdb dn 2016_07_elastic_search
Mdb dn 2016_07_elastic_search
 
introtomongodb
introtomongodbintrotomongodb
introtomongodb
 
How do i Meet MongoDB
How do i Meet MongoDBHow do i Meet MongoDB
How do i Meet MongoDB
 
Introduction to MongoDB.pptx
Introduction to MongoDB.pptxIntroduction to MongoDB.pptx
Introduction to MongoDB.pptx
 
The Care + Feeding of a Mongodb Cluster
The Care + Feeding of a Mongodb ClusterThe Care + Feeding of a Mongodb Cluster
The Care + Feeding of a Mongodb Cluster
 
MongoDB - An Introduction
MongoDB - An IntroductionMongoDB - An Introduction
MongoDB - An Introduction
 
Pandora FMS: MongoDB plugin
Pandora FMS: MongoDB pluginPandora FMS: MongoDB plugin
Pandora FMS: MongoDB plugin
 

Recently uploaded

Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
Product School
 
Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Transcript: Selling digital books in 2024: Insights from industry leaders - T...Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Transcript: Selling digital books in 2024: Insights from industry leaders - T...
BookNet Canada
 
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered QualitySoftware Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
Inflectra
 
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdfFIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance
 
Connector Corner: Automate dynamic content and events by pushing a button
Connector Corner: Automate dynamic content and events by pushing a buttonConnector Corner: Automate dynamic content and events by pushing a button
Connector Corner: Automate dynamic content and events by pushing a button
DianaGray10
 
JMeter webinar - integration with InfluxDB and Grafana
JMeter webinar - integration with InfluxDB and GrafanaJMeter webinar - integration with InfluxDB and Grafana
JMeter webinar - integration with InfluxDB and Grafana
RTTS
 
Neuro-symbolic is not enough, we need neuro-*semantic*
Neuro-symbolic is not enough, we need neuro-*semantic*Neuro-symbolic is not enough, we need neuro-*semantic*
Neuro-symbolic is not enough, we need neuro-*semantic*
Frank van Harmelen
 
UiPath Test Automation using UiPath Test Suite series, part 3
UiPath Test Automation using UiPath Test Suite series, part 3UiPath Test Automation using UiPath Test Suite series, part 3
UiPath Test Automation using UiPath Test Suite series, part 3
DianaGray10
 
Epistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI supportEpistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI support
Alan Dix
 
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
Product School
 
Designing Great Products: The Power of Design and Leadership by Chief Designe...
Designing Great Products: The Power of Design and Leadership by Chief Designe...Designing Great Products: The Power of Design and Leadership by Chief Designe...
Designing Great Products: The Power of Design and Leadership by Chief Designe...
Product School
 
When stars align: studies in data quality, knowledge graphs, and machine lear...
When stars align: studies in data quality, knowledge graphs, and machine lear...When stars align: studies in data quality, knowledge graphs, and machine lear...
When stars align: studies in data quality, knowledge graphs, and machine lear...
Elena Simperl
 
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
DanBrown980551
 
FIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance Osaka Seminar: Overview.pdfFIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance
 
Bits & Pixels using AI for Good.........
Bits & Pixels using AI for Good.........Bits & Pixels using AI for Good.........
Bits & Pixels using AI for Good.........
Alison B. Lowndes
 
Mission to Decommission: Importance of Decommissioning Products to Increase E...
Mission to Decommission: Importance of Decommissioning Products to Increase E...Mission to Decommission: Importance of Decommissioning Products to Increase E...
Mission to Decommission: Importance of Decommissioning Products to Increase E...
Product School
 
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Thierry Lestable
 
The Future of Platform Engineering
The Future of Platform EngineeringThe Future of Platform Engineering
The Future of Platform Engineering
Jemma Hussein Allen
 
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
Product School
 
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdfFIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance
 

Recently uploaded (20)

Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
 
Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Transcript: Selling digital books in 2024: Insights from industry leaders - T...Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Transcript: Selling digital books in 2024: Insights from industry leaders - T...
 
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered QualitySoftware Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
 
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdfFIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
 
Connector Corner: Automate dynamic content and events by pushing a button
Connector Corner: Automate dynamic content and events by pushing a buttonConnector Corner: Automate dynamic content and events by pushing a button
Connector Corner: Automate dynamic content and events by pushing a button
 
JMeter webinar - integration with InfluxDB and Grafana
JMeter webinar - integration with InfluxDB and GrafanaJMeter webinar - integration with InfluxDB and Grafana
JMeter webinar - integration with InfluxDB and Grafana
 
Neuro-symbolic is not enough, we need neuro-*semantic*
Neuro-symbolic is not enough, we need neuro-*semantic*Neuro-symbolic is not enough, we need neuro-*semantic*
Neuro-symbolic is not enough, we need neuro-*semantic*
 
UiPath Test Automation using UiPath Test Suite series, part 3
UiPath Test Automation using UiPath Test Suite series, part 3UiPath Test Automation using UiPath Test Suite series, part 3
UiPath Test Automation using UiPath Test Suite series, part 3
 
Epistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI supportEpistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI support
 
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
 
Designing Great Products: The Power of Design and Leadership by Chief Designe...
Designing Great Products: The Power of Design and Leadership by Chief Designe...Designing Great Products: The Power of Design and Leadership by Chief Designe...
Designing Great Products: The Power of Design and Leadership by Chief Designe...
 
When stars align: studies in data quality, knowledge graphs, and machine lear...
When stars align: studies in data quality, knowledge graphs, and machine lear...When stars align: studies in data quality, knowledge graphs, and machine lear...
When stars align: studies in data quality, knowledge graphs, and machine lear...
 
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
 
FIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance Osaka Seminar: Overview.pdfFIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance Osaka Seminar: Overview.pdf
 
Bits & Pixels using AI for Good.........
Bits & Pixels using AI for Good.........Bits & Pixels using AI for Good.........
Bits & Pixels using AI for Good.........
 
Mission to Decommission: Importance of Decommissioning Products to Increase E...
Mission to Decommission: Importance of Decommissioning Products to Increase E...Mission to Decommission: Importance of Decommissioning Products to Increase E...
Mission to Decommission: Importance of Decommissioning Products to Increase E...
 
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
 
The Future of Platform Engineering
The Future of Platform EngineeringThe Future of Platform Engineering
The Future of Platform Engineering
 
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
 
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdfFIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
 

MongoDB basics & Introduction

  • 1. basics JERWIN ROY J Database Adminstrator meetjerwin@gmail.com
  • 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