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" ]
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
Fastsync will be deprecated at some point in the future.\n\nkeyFile is only for sharding >= 2.0\n
--keyFile since 1.9.x\n
\n
--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
dump using a query\n\nnote, it runs the query so will be slow if un-indexed and lots of data\n
oplogReplay -- point in time restore\n\ncustom _id -- can use --forceTableScan which will help\n
\n
\n
\n
\n
\n
\n
\n
\n
\n
\n
\n
\n
\n
\n
\n
\n
\n
PROTOTYPE ONLY\n\nRestart is an interesting topic. &#xA0;Tungsten uses a table to store the sequence number of the last transaction it applied. &#xA0;We do this by creating an equivalent collection in MongoDB, which is updated after each commit. &#xA0;There is a problem in that MongoDB does not have transactions. &#xA0;Each update is effectively auto-commit, much like MyISAM table type on MySQL. &#xA0;This means that while Tungsten can restart properly after a clean shutdown, slave replication is not crash safe. &#xA0;Lack of atomic transactions is&#xA0;a bigger issue with MongoDB and other NoSQL databases that goes far beyond replication. &#xA0;For now, this is just how Tungsten's MongoDB support works.\n