SlideShare uma empresa Scribd logo
1 de 37
mongo*
Just what do those commands do?
           By Russell Smith
/usr/bin/whoami

•   Russell Smith

•   Consultant for UKD1 Limited

•   I Specialise in helping companies going through rapid growth;

•   Code, architecture, infrastructure, devops, sysops, capacity planning, etc

•   <3 MongoDB, Neo4j, MySQL, Riak, Gearman, Kohana, PHP, Debian, Puppet, etc...
Huh?

•   MongoDB ships with a variety of CLI tools

•   Some popular;
    mongodump, mongorestore, mongostat, mongo

•   Some less so;
    mongosniff, mongoexport, mongoimport, bsondump, etc
Core
mongo

•   Probably the most commonly used

•   ‘Hidden’ gems;

    •   ~/.mongorc.js - will be executed by default

    •   --eval “some js” - evaluates Javascript and exits
mongo (cont.)
~ mongo test --eval "printjson(db.getCollectionNames())"
MongoDB shell version: 2.1.0-pre-
connecting to: test
[ "fs.chunks", "fs.files", "system.indexes", "system.profile", "test" ]



~ mongo test --quiet --eval "printjson(db.getCollectionNames())"
[ "fs.chunks", "fs.files", "system.indexes", "system.profile", "test" ]
~/.mongorc.js
x = db.queue.count({state:4});

if (x > 0)
{
  print('WARNING: ' + x + ' hung jobs');
}
~/.mongorc.js

~ mongo
MongoDB shell version: 2.1.0-pre-
connecting to: test
WARNING: 2 hung jobs
>
mongod

•   The server itself

•   Useful:

    •   --fastsync - allows (much) faster starting of a replset member by
        using a (recent) snapshot of a peer

    •   --keyFile - replset / sharding authentication file
mongos


•   Sits in front of your shard servers and directs queries

•   --keyFile
Common
mongodump

•   Used to take backups

•   Common options:

    •   --oplog

    •   -d

    •   -c
mongodump (cont.)

~ mongodump -d test -c queue -q "{state:4}"
connected to: 127.0.0.1
DATABASE: test
 to 
 dump/test

 test.queue to dump/test/queue.bson

 
 2 objects
mongorestore

•   Restores backups taken with mongodump

•   Interesting options;

    •   --filter

    •   --oplogReplay

•   Possible performance issues with custom (non ObjectId) _id
mongorestore (cont.)
mongorestore -d test -c queue --filter "{state:4}" dump/test/queue.bson
connected to: 127.0.0.1
Mon Sep 19 07:34:03 dump/test/queue.bson
Mon Sep 19 07:34:03 
 going into namespace [test.queue]
764 objects found
2 objects processed
mongostat


•   Produces periodically updated stats

•   Useful in watching server load & spotting general performance issues
Common       Cursor        Total
operations   paging      data size            queues




                       fsync                           active
                                     locked
                      flushes                           clients
mongostat (cont’d)

•   Watch for;

    •   faults (page faults)

    •   idx miss (index btree page misses)

    •   locked (percentage of time globally locked)

    •   repl (it should normally be M or SEC)
Others
mongoexport

•   Useful to export data for use with another database or program

•   You may specify down to the field level using a filter if needed

•   Can export as;

    •   JSON (default)

    •   CSV
mongoimport

•   Imports data in to mongodb

•   Currently supports importing;

    •   JSON

    •   CSV

    •   TSV
mongoimport (cont’d)

•   Useful options include;

    •   --upsert - allows updating objects that exist already
        (see --upsertFields)


    •   --headerline - if your CSV / TSV contains headers

    •   -f / --fields - specify field names
bsondump

                             bsondump test.bson --type json
                             { "_id" :
                             ObjectId( "4e72f51414345f302b0eea2e" ),
•   Convert bson -> json
                             "test" : 1 }
                             1 objects found
bsondump (cont.)

                         bsondump test.bson --type debug
                         --- new object ---
                         
 size : 36
                         
 
 _id
•   Debug info:
                         
 
 
 type: 7 size: 17
                         
 
 test
                         
 
 
 type: 1 size: 14
                         etc
mongofiles
~ mongofiles put test.txt

connected to: 127.0.0.1
added file: { _id: ObjectId('4e761b07c21062d06b349819'), filename:
"test.txt", chunkSize: 262144, uploadDate: new Date(1316363015625),
md5: "d41d8cd98f00b204e9800998ecf8427e", length: 12256 }
done!
mongofiles (cont.)

~ mongofiles list

connected to: 127.0.0.1
test.txt
 12256
mongotop


•   New in 1.9

•   Collection level load stats
mongosniff


•   Used for sniffing the traffic between client / server

•   Can forward traffic

•   Only really useful for debugging...
mongo-perf


•   Does not ship with mongodb
    See : https://github.com/mongodb/mongo-perf



•   I can’t compile it, but it probably works
Useful third party tools
tungsten replicator
mysql> create table foo(id int primary key, msg varchar(35));
Query OK, 0 rows affected (0.05 sec)
mysql> insert into foo values(1, 'hello from MySQL!');
Query OK, 1 row affected (0.00 sec)



> db.foo.find()
{ "_id" : ObjectId("4dc77bacad9092bd1aef046d"), "id" : "1", "data" :
"hello from MySQL!" }



•   http://code.google.com/p/tungsten-replicator/

•   http://code.google.com/p/tungsten-replicator/wiki/
automongobackup


•   A port of the popular AutoMySQLBackup

•   Rotates & compresses backups

•   https://github.com/micahwedemeyer/automongobackup
mongolog


•   Full query logging

•   Uses mongosniff

•   Will be on github soon
Other interesting projects


•   Eliots Munin plugins : https://github.com/erh/mongo-munin

•   gridfs-fuse : https://github.com/mikejs/gridfs-fuse
Further reading
•   Tungsten with Mongo details
    http://scale-out-blog.blogspot.com/2011/05/introducing-mysql-to-mongodb.html


•   Javascript shell API
    http://api.mongodb.org/js/current/


•   Admin UI’s
    http://www.mongodb.org/display/DOCS/Admin+UIs


•   Hacking the shell
    http://bit.ly/r2vghH
Questions?

Mais conteúdo relacionado

Mais procurados

mongoDB Performance
mongoDB PerformancemongoDB Performance
mongoDB Performance
Moshe Kaplan
 
MongoDB Performance Tuning and Monitoring
MongoDB Performance Tuning and MonitoringMongoDB Performance Tuning and Monitoring
MongoDB Performance Tuning and Monitoring
MongoDB
 
Benefits of using MongoDB: Reduce Complexity & Adapt to Changes
Benefits of using MongoDB: Reduce Complexity & Adapt to ChangesBenefits of using MongoDB: Reduce Complexity & Adapt to Changes
Benefits of using MongoDB: Reduce Complexity & Adapt to Changes
Alex Nguyen
 
Distributed computing in browsers as client side attack
Distributed computing in browsers as client side attackDistributed computing in browsers as client side attack
Distributed computing in browsers as client side attack
Ivan Novikov
 
MongoDB Memory Management Demystified
MongoDB Memory Management DemystifiedMongoDB Memory Management Demystified
MongoDB Memory Management Demystified
MongoDB
 

Mais procurados (20)

Mongodb
MongodbMongodb
Mongodb
 
MongoDB's New Aggregation framework
MongoDB's New Aggregation frameworkMongoDB's New Aggregation framework
MongoDB's New Aggregation framework
 
MongoDB World 2016: From the Polls to the Trolls: Seeing What the World Think...
MongoDB World 2016: From the Polls to the Trolls: Seeing What the World Think...MongoDB World 2016: From the Polls to the Trolls: Seeing What the World Think...
MongoDB World 2016: From the Polls to the Trolls: Seeing What the World Think...
 
Understanding and tuning WiredTiger, the new high performance database engine...
Understanding and tuning WiredTiger, the new high performance database engine...Understanding and tuning WiredTiger, the new high performance database engine...
Understanding and tuning WiredTiger, the new high performance database engine...
 
Connecting NodeJS & MongoDB
Connecting NodeJS & MongoDBConnecting NodeJS & MongoDB
Connecting NodeJS & MongoDB
 
mongoDB Performance
mongoDB PerformancemongoDB Performance
mongoDB Performance
 
Putting the Go in MongoDB: How We Rebuilt The MongoDB Tools in Go
Putting the Go in MongoDB: How We Rebuilt The MongoDB Tools in GoPutting the Go in MongoDB: How We Rebuilt The MongoDB Tools in Go
Putting the Go in MongoDB: How We Rebuilt The MongoDB Tools in Go
 
MongoDB Performance Tuning and Monitoring
MongoDB Performance Tuning and MonitoringMongoDB Performance Tuning and Monitoring
MongoDB Performance Tuning and Monitoring
 
Node js crash course session 2
Node js crash course   session 2Node js crash course   session 2
Node js crash course session 2
 
Using MongoDB and a Relational Database at MongoDB Day
Using MongoDB and a Relational Database at MongoDB DayUsing MongoDB and a Relational Database at MongoDB Day
Using MongoDB and a Relational Database at MongoDB Day
 
Node js crash course session 5
Node js crash course   session 5Node js crash course   session 5
Node js crash course session 5
 
Benefits of using MongoDB: Reduce Complexity & Adapt to Changes
Benefits of using MongoDB: Reduce Complexity & Adapt to ChangesBenefits of using MongoDB: Reduce Complexity & Adapt to Changes
Benefits of using MongoDB: Reduce Complexity & Adapt to Changes
 
Back to Basics Webinar 6: Production Deployment
Back to Basics Webinar 6: Production DeploymentBack to Basics Webinar 6: Production Deployment
Back to Basics Webinar 6: Production Deployment
 
Back to Basics Spanish 4 Introduction to sharding
Back to Basics Spanish 4 Introduction to shardingBack to Basics Spanish 4 Introduction to sharding
Back to Basics Spanish 4 Introduction to sharding
 
Whats new in MongoDB 24
Whats new in MongoDB 24Whats new in MongoDB 24
Whats new in MongoDB 24
 
Distributed computing in browsers as client side attack
Distributed computing in browsers as client side attackDistributed computing in browsers as client side attack
Distributed computing in browsers as client side attack
 
Sharding
ShardingSharding
Sharding
 
Back to Basics Spanish Webinar 3 - Introducción a los replica sets
Back to Basics Spanish Webinar 3 - Introducción a los replica setsBack to Basics Spanish Webinar 3 - Introducción a los replica sets
Back to Basics Spanish Webinar 3 - Introducción a los replica sets
 
MongoDB Memory Management Demystified
MongoDB Memory Management DemystifiedMongoDB Memory Management Demystified
MongoDB Memory Management Demystified
 
HTTP 완벽가이드- 13 다이제스트 인증
HTTP 완벽가이드- 13 다이제스트 인증HTTP 완벽가이드- 13 다이제스트 인증
HTTP 완벽가이드- 13 다이제스트 인증
 

Semelhante a MongoDB Command Line Tools

High Performance, Scalable MongoDB in a Bare Metal Cloud
High Performance, Scalable MongoDB in a Bare Metal CloudHigh Performance, Scalable MongoDB in a Bare Metal Cloud
High Performance, Scalable MongoDB in a Bare Metal Cloud
MongoDB
 
Deployment Strategy
Deployment StrategyDeployment Strategy
Deployment Strategy
MongoDB
 
Shell Tips & Tricks
Shell Tips & TricksShell Tips & Tricks
Shell Tips & Tricks
MongoDB
 
MongoDB and Ruby on Rails
MongoDB and Ruby on RailsMongoDB and Ruby on Rails
MongoDB and Ruby on Rails
rfischer20
 
Basic Sharding in MongoDB presented by Shaun Verch
Basic Sharding in MongoDB presented by Shaun VerchBasic Sharding in MongoDB presented by Shaun Verch
Basic Sharding in MongoDB presented by Shaun Verch
MongoDB
 

Semelhante a MongoDB Command Line Tools (20)

High Performance, Scalable MongoDB in a Bare Metal Cloud
High Performance, Scalable MongoDB in a Bare Metal CloudHigh Performance, Scalable MongoDB in a Bare Metal Cloud
High Performance, Scalable MongoDB in a Bare Metal Cloud
 
MongoDB: a gentle, friendly overview
MongoDB: a gentle, friendly overviewMongoDB: a gentle, friendly overview
MongoDB: a gentle, friendly overview
 
MongoDB Pros and Cons
MongoDB Pros and ConsMongoDB Pros and Cons
MongoDB Pros and Cons
 
Get expertise with mongo db
Get expertise with mongo dbGet expertise with mongo db
Get expertise with mongo db
 
Webinar: What's new in the .NET Driver
Webinar: What's new in the .NET DriverWebinar: What's new in the .NET Driver
Webinar: What's new in the .NET Driver
 
2016 feb-23 pyugre-py_mongo
2016 feb-23 pyugre-py_mongo2016 feb-23 pyugre-py_mongo
2016 feb-23 pyugre-py_mongo
 
Using MongoDB and Python
Using MongoDB and PythonUsing MongoDB and Python
Using MongoDB and Python
 
NOSQL101, Or: How I Learned To Stop Worrying And Love The Mongo!
NOSQL101, Or: How I Learned To Stop Worrying And Love The Mongo!NOSQL101, Or: How I Learned To Stop Worrying And Love The Mongo!
NOSQL101, Or: How I Learned To Stop Worrying And Love The Mongo!
 
Deployment Strategy
Deployment StrategyDeployment Strategy
Deployment Strategy
 
Creating a Benchmarking Infrastructure That Just Works
Creating a Benchmarking Infrastructure That Just WorksCreating a Benchmarking Infrastructure That Just Works
Creating a Benchmarking Infrastructure That Just Works
 
Shell Tips & Tricks
Shell Tips & TricksShell Tips & Tricks
Shell Tips & Tricks
 
Whats new in mongoDB 2.4 at Copenhagen user group 2013-06-19
Whats new in mongoDB 2.4 at Copenhagen user group 2013-06-19Whats new in mongoDB 2.4 at Copenhagen user group 2013-06-19
Whats new in mongoDB 2.4 at Copenhagen user group 2013-06-19
 
MongoDB Tokyo - Monitoring and Queueing
MongoDB Tokyo - Monitoring and QueueingMongoDB Tokyo - Monitoring and Queueing
MongoDB Tokyo - Monitoring and Queueing
 
Mongo db roma replication and sharding
Mongo db roma replication and shardingMongo db roma replication and sharding
Mongo db roma replication and sharding
 
Dev Jumpstart: Build Your First App with MongoDB
Dev Jumpstart: Build Your First App with MongoDBDev Jumpstart: Build Your First App with MongoDB
Dev Jumpstart: Build Your First App with MongoDB
 
Deployment Strategies
Deployment StrategiesDeployment Strategies
Deployment Strategies
 
5 Pitfalls to Avoid with MongoDB
5 Pitfalls to Avoid with MongoDB5 Pitfalls to Avoid with MongoDB
5 Pitfalls to Avoid with MongoDB
 
Webinaire 2 de la série « Retour aux fondamentaux » : Votre première applicat...
Webinaire 2 de la série « Retour aux fondamentaux » : Votre première applicat...Webinaire 2 de la série « Retour aux fondamentaux » : Votre première applicat...
Webinaire 2 de la série « Retour aux fondamentaux » : Votre première applicat...
 
MongoDB and Ruby on Rails
MongoDB and Ruby on RailsMongoDB and Ruby on Rails
MongoDB and Ruby on Rails
 
Basic Sharding in MongoDB presented by Shaun Verch
Basic Sharding in MongoDB presented by Shaun VerchBasic Sharding in MongoDB presented by Shaun Verch
Basic Sharding in MongoDB presented by Shaun Verch
 

Mais de Rainforest QA

Pivotal Labs Lunch Talk; 3 Infrastructure and workflow lessons learned at an ...
Pivotal Labs Lunch Talk; 3 Infrastructure and workflow lessons learned at an ...Pivotal Labs Lunch Talk; 3 Infrastructure and workflow lessons learned at an ...
Pivotal Labs Lunch Talk; 3 Infrastructure and workflow lessons learned at an ...
Rainforest QA
 
Seedhack MongoDB 2011
Seedhack MongoDB 2011Seedhack MongoDB 2011
Seedhack MongoDB 2011
Rainforest QA
 
Geo & capped collections with MongoDB
Geo & capped collections  with MongoDBGeo & capped collections  with MongoDB
Geo & capped collections with MongoDB
Rainforest QA
 

Mais de Rainforest QA (11)

Machine Learning in Practice - CTO Summit Chicago 2019
Machine Learning in Practice - CTO Summit Chicago 2019Machine Learning in Practice - CTO Summit Chicago 2019
Machine Learning in Practice - CTO Summit Chicago 2019
 
CTO Summit NASDAQ NYC 2017: Creating a QA Strategy
CTO Summit NASDAQ NYC 2017: Creating a QA StrategyCTO Summit NASDAQ NYC 2017: Creating a QA Strategy
CTO Summit NASDAQ NYC 2017: Creating a QA Strategy
 
Ops Skills and Tools for Beginners [#MongoDB World 2014]
Ops Skills and Tools for Beginners [#MongoDB World 2014]Ops Skills and Tools for Beginners [#MongoDB World 2014]
Ops Skills and Tools for Beginners [#MongoDB World 2014]
 
Pragmatic Rails Architecture [SF Rails, 24 Apr 14]
Pragmatic Rails Architecture [SF Rails, 24 Apr 14]Pragmatic Rails Architecture [SF Rails, 24 Apr 14]
Pragmatic Rails Architecture [SF Rails, 24 Apr 14]
 
Bitcoin Ops & Security Primer
Bitcoin Ops & Security PrimerBitcoin Ops & Security Primer
Bitcoin Ops & Security Primer
 
Pivotal Labs Lunch Talk; 3 Infrastructure and workflow lessons learned at an ...
Pivotal Labs Lunch Talk; 3 Infrastructure and workflow lessons learned at an ...Pivotal Labs Lunch Talk; 3 Infrastructure and workflow lessons learned at an ...
Pivotal Labs Lunch Talk; 3 Infrastructure and workflow lessons learned at an ...
 
Seedhack MongoDB 2011
Seedhack MongoDB 2011Seedhack MongoDB 2011
Seedhack MongoDB 2011
 
An Introduction to Map/Reduce with MongoDB
An Introduction to Map/Reduce with MongoDBAn Introduction to Map/Reduce with MongoDB
An Introduction to Map/Reduce with MongoDB
 
How does Riak compare to Cassandra? [Cassandra London User Group July 2011]
How does Riak compare to Cassandra? [Cassandra London User Group July 2011]How does Riak compare to Cassandra? [Cassandra London User Group July 2011]
How does Riak compare to Cassandra? [Cassandra London User Group July 2011]
 
London MongoDB User Group April 2011
London MongoDB User Group April 2011London MongoDB User Group April 2011
London MongoDB User Group April 2011
 
Geo & capped collections with MongoDB
Geo & capped collections  with MongoDBGeo & capped collections  with MongoDB
Geo & capped collections with MongoDB
 

Último

Último (20)

Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : Uncertainty
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
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
 
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
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
 
Manulife - Insurer Innovation Award 2024
Manulife - Insurer Innovation Award 2024Manulife - Insurer Innovation Award 2024
Manulife - Insurer Innovation Award 2024
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
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...
 

MongoDB Command Line Tools

  • 1. mongo* Just what do those commands do? By Russell Smith
  • 2. /usr/bin/whoami • Russell Smith • Consultant for UKD1 Limited • I Specialise in helping companies going through rapid growth; • Code, architecture, infrastructure, devops, sysops, capacity planning, etc • <3 MongoDB, Neo4j, MySQL, Riak, Gearman, Kohana, PHP, Debian, Puppet, etc...
  • 3. Huh? • MongoDB ships with a variety of CLI tools • Some popular; mongodump, mongorestore, mongostat, mongo • Some less so; mongosniff, mongoexport, mongoimport, bsondump, etc
  • 5. mongo • Probably the most commonly used • ‘Hidden’ gems; • ~/.mongorc.js - will be executed by default • --eval “some js” - evaluates Javascript and exits
  • 6. mongo (cont.) ~ mongo test --eval "printjson(db.getCollectionNames())" MongoDB shell version: 2.1.0-pre- connecting to: test [ "fs.chunks", "fs.files", "system.indexes", "system.profile", "test" ] ~ mongo test --quiet --eval "printjson(db.getCollectionNames())" [ "fs.chunks", "fs.files", "system.indexes", "system.profile", "test" ]
  • 7. ~/.mongorc.js x = db.queue.count({state:4}); if (x > 0) { print('WARNING: ' + x + ' hung jobs'); }
  • 8. ~/.mongorc.js ~ mongo MongoDB shell version: 2.1.0-pre- connecting to: test WARNING: 2 hung jobs >
  • 9. mongod • The server itself • Useful: • --fastsync - allows (much) faster starting of a replset member by using a (recent) snapshot of a peer • --keyFile - replset / sharding authentication file
  • 10. mongos • Sits in front of your shard servers and directs queries • --keyFile
  • 12. mongodump • Used to take backups • Common options: • --oplog • -d • -c
  • 13. mongodump (cont.) ~ mongodump -d test -c queue -q "{state:4}" connected to: 127.0.0.1 DATABASE: test to dump/test test.queue to dump/test/queue.bson 2 objects
  • 14. mongorestore • Restores backups taken with mongodump • Interesting options; • --filter • --oplogReplay • Possible performance issues with custom (non ObjectId) _id
  • 15. mongorestore (cont.) mongorestore -d test -c queue --filter "{state:4}" dump/test/queue.bson connected to: 127.0.0.1 Mon Sep 19 07:34:03 dump/test/queue.bson Mon Sep 19 07:34:03 going into namespace [test.queue] 764 objects found 2 objects processed
  • 16. mongostat • Produces periodically updated stats • Useful in watching server load & spotting general performance issues
  • 17. Common Cursor Total operations paging data size queues fsync active locked flushes clients
  • 18. mongostat (cont’d) • Watch for; • faults (page faults) • idx miss (index btree page misses) • locked (percentage of time globally locked) • repl (it should normally be M or SEC)
  • 20. mongoexport • Useful to export data for use with another database or program • You may specify down to the field level using a filter if needed • Can export as; • JSON (default) • CSV
  • 21. mongoimport • Imports data in to mongodb • Currently supports importing; • JSON • CSV • TSV
  • 22. mongoimport (cont’d) • Useful options include; • --upsert - allows updating objects that exist already (see --upsertFields) • --headerline - if your CSV / TSV contains headers • -f / --fields - specify field names
  • 23. bsondump bsondump test.bson --type json { "_id" : ObjectId( "4e72f51414345f302b0eea2e" ), • Convert bson -> json "test" : 1 } 1 objects found
  • 24. bsondump (cont.) bsondump test.bson --type debug --- new object --- size : 36 _id • Debug info: type: 7 size: 17 test type: 1 size: 14 etc
  • 25. mongofiles ~ mongofiles put test.txt connected to: 127.0.0.1 added file: { _id: ObjectId('4e761b07c21062d06b349819'), filename: "test.txt", chunkSize: 262144, uploadDate: new Date(1316363015625), md5: "d41d8cd98f00b204e9800998ecf8427e", length: 12256 } done!
  • 26. mongofiles (cont.) ~ mongofiles list connected to: 127.0.0.1 test.txt 12256
  • 27. mongotop • New in 1.9 • Collection level load stats
  • 28. mongosniff • Used for sniffing the traffic between client / server • Can forward traffic • Only really useful for debugging...
  • 29.
  • 30. mongo-perf • Does not ship with mongodb See : https://github.com/mongodb/mongo-perf • I can’t compile it, but it probably works
  • 32. tungsten replicator mysql> create table foo(id int primary key, msg varchar(35)); Query OK, 0 rows affected (0.05 sec) mysql> insert into foo values(1, 'hello from MySQL!'); Query OK, 1 row affected (0.00 sec) > db.foo.find() { "_id" : ObjectId("4dc77bacad9092bd1aef046d"), "id" : "1", "data" : "hello from MySQL!" } • http://code.google.com/p/tungsten-replicator/ • http://code.google.com/p/tungsten-replicator/wiki/
  • 33. automongobackup • A port of the popular AutoMySQLBackup • Rotates & compresses backups • https://github.com/micahwedemeyer/automongobackup
  • 34. mongolog • Full query logging • Uses mongosniff • Will be on github soon
  • 35. Other interesting projects • Eliots Munin plugins : https://github.com/erh/mongo-munin • gridfs-fuse : https://github.com/mikejs/gridfs-fuse
  • 36. Further reading • Tungsten with Mongo details http://scale-out-blog.blogspot.com/2011/05/introducing-mysql-to-mongodb.html • Javascript shell API http://api.mongodb.org/js/current/ • Admin UI’s http://www.mongodb.org/display/DOCS/Admin+UIs • Hacking the shell http://bit.ly/r2vghH

Notas do Editor

  1. \n
  2. \n
  3. \n
  4. \n
  5. \n
  6. \n
  7. \n
  8. \n
  9. Fastsync will be deprecated at some point in the future.\n\nkeyFile is only for sharding &gt;= 2.0\n
  10. --keyFile since 1.9.x\n
  11. \n
  12. --oplog (creates a point in time snapshot using the oplog)\n-d specify a database, if omitted all are dumped\n-c (specify a collection, if omitted all are dumped)\n
  13. dump using a query\n\nnote, it runs the query so will be slow if un-indexed and lots of data\n
  14. oplogReplay -- point in time restore\n\ncustom _id -- can use --forceTableScan which will help\n
  15. \n
  16. \n
  17. \n
  18. \n
  19. \n
  20. \n
  21. \n
  22. \n
  23. \n
  24. \n
  25. \n
  26. \n
  27. \n
  28. \n
  29. \n
  30. \n
  31. \n
  32. PROTOTYPE ONLY\n\nRestart is an interesting topic. &amp;#xA0;Tungsten uses a table to store the sequence number of the last transaction it applied. &amp;#xA0;We do this by creating an equivalent collection in MongoDB, which is updated after each commit. &amp;#xA0;There is a problem in that MongoDB does not have transactions. &amp;#xA0;Each update is effectively auto-commit, much like MyISAM table type on MySQL. &amp;#xA0;This means that while Tungsten can restart properly after a clean shutdown, slave replication is not crash safe. &amp;#xA0;Lack of atomic transactions is&amp;#xA0;a bigger issue with MongoDB and other NoSQL databases that goes far beyond replication. &amp;#xA0;For now, this is just how Tungsten&apos;s MongoDB support works.\n
  33. \n
  34. \n
  35. \n
  36. \n
  37. \n