SlideShare uma empresa Scribd logo
1 de 33
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

Mais conteúdo relacionado

Mais procurados (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
 

Destaque

Training MongoDB - Monitoring and Operability
Training MongoDB - Monitoring and OperabilityTraining MongoDB - Monitoring and Operability
Training MongoDB - Monitoring and OperabilityNicolas 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 engineersMoshe Kaplan
 
Server discovery and monitoring with MongoDB
Server discovery and monitoring with MongoDBServer discovery and monitoring with MongoDB
Server discovery and monitoring with MongoDBJoe 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 & docSTARdocSTAR
 
iMIS 20 Overview for Education Associations
iMIS 20 Overview for Education AssociationsiMIS 20 Overview for Education Associations
iMIS 20 Overview for Education AssociationsiMIS
 
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 SecondsCarval 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
 
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 workforceAccess 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 SingaporeOne9Ninety
 
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íderSafi
 

Destaque (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
 

Semelhante a MongoDB basics & Introduction

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 DatabaseFITC
 
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 windowsprabakaranbrick
 
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 Consjohnrjenson
 
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 EC2ShepHertz
 
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 minutesSudheer Kondla
 
Mdb dn 2016_07_elastic_search
Mdb dn 2016_07_elastic_searchMdb dn 2016_07_elastic_search
Mdb dn 2016_07_elastic_searchDaniel M. Farrell
 
introtomongodb
introtomongodbintrotomongodb
introtomongodbsaikiran
 
Introduction to MongoDB.pptx
Introduction to MongoDB.pptxIntroduction to MongoDB.pptx
Introduction to MongoDB.pptxSurya937648
 
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 Introductiondinkar thakur
 
Pandora FMS: MongoDB plugin
Pandora FMS: MongoDB pluginPandora FMS: MongoDB plugin
Pandora FMS: MongoDB pluginPandora FMS
 

Semelhante a 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
 

Último

"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ..."I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...Zilliz
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MIND CTI
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processorsdebabhi2
 
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdfRising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdfOrbitshub
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FMESafe Software
 
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWEREMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWERMadyBayot
 
MS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectorsMS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectorsNanddeep Nachan
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherRemote DBA Services
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...apidays
 
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Jeffrey Haguewood
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FMESafe Software
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoffsammart93
 
ICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesrafiqahmad00786416
 
CNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In PakistanCNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In Pakistandanishmna97
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native ApplicationsWSO2
 
Cyberprint. Dark Pink Apt Group [EN].pdf
Cyberprint. Dark Pink Apt Group [EN].pdfCyberprint. Dark Pink Apt Group [EN].pdf
Cyberprint. Dark Pink Apt Group [EN].pdfOverkill Security
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...DianaGray10
 
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...apidays
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyKhushali Kathiriya
 

Último (20)

"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ..."I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdfRising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWEREMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
 
MS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectorsMS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectors
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
 
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
ICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesICT role in 21st century education and its challenges
ICT role in 21st century education and its challenges
 
CNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In PakistanCNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In Pakistan
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
 
Cyberprint. Dark Pink Apt Group [EN].pdf
Cyberprint. Dark Pink Apt Group [EN].pdfCyberprint. Dark Pink Apt Group [EN].pdf
Cyberprint. Dark Pink Apt Group [EN].pdf
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : Uncertainty
 

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