Lock in $30 Savings on PRO—Offer Ends Soon! ⏳
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
MongoDB London 2011 - MongoDB Command Line Tools
Search
Russell Smith
April 20, 2012
Technology
1
150
MongoDB London 2011 - MongoDB Command Line Tools
Russell Smith
April 20, 2012
Tweet
Share
More Decks by Russell Smith
See All by Russell Smith
Ops Skills and Tools for Beginners [MongoDB World 2014]
ukd1
0
92
3 Infrastructure + workflow lessons from an early stage startup
ukd1
0
86
Bitcoin Ops & Security Primer
ukd1
1
140
Gearman & Kohana
ukd1
2
900
Geo & capped collections with MongoDB
ukd1
1
110
Cassandra London UG July 2011 - Riak vs Cassandra
ukd1
1
250
MongoDB - Map Reduce
ukd1
2
180
MongoDB London UG, April 2011 - MongoDB Introduction
ukd1
1
70
Seedhack 2011 - Introducing MongoDB
ukd1
1
93
Other Decks in Technology
See All in Technology
生成AIを活用したIT運用高度化への挑戦
iotcomjpadmin
0
270
12/2(月)のBedrockアプデ速報(re:Invent 2024 Daily re:Cap #1 with AWS Heroes)
minorun365
PRO
1
200
ONNX推論クレートの比較と実装奮闘記
emergent
0
260
ポストモーテムレビューをブレームレスに運営し有効な改善アクションを引き出すために必要だったこと / What is needed to operate postmortem blamelessly and elicit improvement actions
yamaguchitk333
0
120
LLMの気持ちになってRAGのことを考えてみよう
john_smith
0
190
Amazon CloudFrontを活用したゼロダウンタイム実現する安定的なデプロイメント / 20241129 Yoshiki Shinagawa
shift_evolve
0
110
メインテーマはKubernetes
nwiizo
2
310
TypeScript100%で作るMovable Typeプラグイン
usualoma
2
260
データカタログを自作したけど 運用しなかった話@Findy Lunch LT「データカタログ 事例から学ぶメタデータ管理の実態」
ryo_suzuki
2
400
セキュリティベンダー/ユーザー双方の視点で語る、 Attack Surface Managementの実践 - Finatextパート / cloudnative-architecture-of-asm
stajima
0
2.5k
全社員に向けて生成AI活用を促進!~電通総研の生成AI活用ロードマップ~
iotcomjpadmin
0
270
エンジニアの草の根活動のその先へ LINEギフトのアクセシビリティにおける ネクストアクション
lycorptech_jp
PRO
0
110
Featured
See All Featured
Design and Strategy: How to Deal with People Who Don’t "Get" Design
morganepeng
126
18k
What's new in Ruby 2.0
geeforr
343
31k
Testing 201, or: Great Expectations
jmmastey
40
7.1k
A Philosophy of Restraint
colly
203
16k
4 Signs Your Business is Dying
shpigford
181
21k
Git: the NoSQL Database
bkeepers
PRO
427
64k
The Cost Of JavaScript in 2023
addyosmani
45
6.9k
Code Review Best Practice
trishagee
64
17k
Learning to Love Humans: Emotional Interface Design
aarron
273
40k
[RailsConf 2023] Rails as a piece of cake
palkan
52
5k
A designer walks into a library…
pauljervisheath
204
24k
実際に使うSQLの書き方 徹底解説 / pgcon21j-tutorial
soudai
169
50k
Transcript
mongo* Just what do those commands do? By Russell Smith
Friday, 20 April 12
/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... Friday, 20 April 12
Huh? • MongoDB ships with a variety of CLI tools
• Some popular; mongodump, mongorestore, mongostat, mongo • Some less so; mongosniff, mongoexport, mongoimport, bsondump, etc Friday, 20 April 12
Core Friday, 20 April 12
mongo • Probably the most commonly used • ‘Hidden’ gems;
• ~/.mongorc.js - will be executed by default • --eval “some js” - evaluates Javascript and exits Friday, 20 April 12
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" ] Friday, 20 April 12
~/.mongorc.js x = db.queue.count({state:4}); if (x > 0) { print('WARNING:
' + x + ' hung jobs'); } Friday, 20 April 12
~/.mongorc.js ~ mongo MongoDB shell version: 2.1.0-pre- connecting to: test
WARNING: 2 hung jobs > Friday, 20 April 12
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 Friday, 20 April 12
mongos • Sits in front of your shard servers and
directs queries • --keyFile Friday, 20 April 12
Common Friday, 20 April 12
mongodump • Used to take backups • Common options: •
--oplog • -d • -c Friday, 20 April 12
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 Friday, 20 April 12
mongorestore • Restores backups taken with mongodump • Interesting options;
• --filter • --oplogReplay • Possible performance issues with custom (non ObjectId) _id Friday, 20 April 12
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 Friday, 20 April 12
mongostat • Produces periodically updated stats • Useful in watching
server load & spotting general performance issues Friday, 20 April 12
Cursor paging Common operations fsync flushes Total data size locked
active clients queues Friday, 20 April 12
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) Friday, 20 April 12
Others Friday, 20 April 12
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 Friday, 20 April 12
mongoimport • Imports data in to mongodb • Currently supports
importing; • JSON • CSV • TSV Friday, 20 April 12
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 Friday, 20 April 12
bsondump • Convert bson -> json bsondump test.bson --type json
{ "_id" : ObjectId( "4e72f51414345f302b0eea2e" ), "test" : 1 } 1 objects found Friday, 20 April 12
bsondump (cont.) • Debug info: bsondump test.bson --type debug ---
new object --- size : 36 _id type: 7 size: 17 test type: 1 size: 14 etc Friday, 20 April 12
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! Friday, 20 April 12
mongofiles (cont.) ~ mongofiles list connected to: 127.0.0.1 test.txt 12256
Friday, 20 April 12
mongotop • New in 1.9 • Collection level load stats
Friday, 20 April 12
mongosniff • Used for sniffing the traffic between client /
server • Can forward traffic • Only really useful for debugging... Friday, 20 April 12
Friday, 20 April 12
mongo-perf • Does not ship with mongodb See : https://github.com/mongodb/mongo-perf
• I can’t compile it, but it probably works Friday, 20 April 12
Useful third party tools Friday, 20 April 12
tungsten replicator • http://code.google.com/p/tungsten-replicator/ • http://code.google.com/p/tungsten-replicator/wiki/ 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!" } Friday, 20 April 12
automongobackup • A port of the popular AutoMySQLBackup • Rotates
& compresses backups • https://github.com/micahwedemeyer/automongobackup Friday, 20 April 12
mongolog • Full query logging • Uses mongosniff • Will
be on github soon Friday, 20 April 12
Other interesting projects • Eliots Munin plugins : https://github.com/erh/mongo-munin •
gridfs-fuse : https://github.com/mikejs/gridfs-fuse Friday, 20 April 12
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 Friday, 20 April 12
Questions? Friday, 20 April 12