-
-
Save agius/1468681 to your computer and use it in GitHub Desktop.
MongoDB shell cheatsheet
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// A bunch of functions you can use in the MongoDB shell | |
// taken from http://api.mongodb.org/js/1.8.2/index.html | |
// amongst other sources | |
// Used in place of print() to view the contents of objects | |
printjson(x); | |
printjsononeline(x); | |
// File system interaction | |
ls(...); | |
pwd(); | |
cd(...); | |
removeFile(...); | |
mkdir(...); | |
// Misc | |
hex_md5('foo'); | |
//basic query | |
db.stream_objs.find().sort({created_at: -1}).limit(1) | |
// advanced queries at http://www.mongodb.org/display/DOCS/Advanced+Queries | |
// ops | |
db.currentOp() | |
db.getLastError() | |
db.mycollection.runCommand("compact") | |
//replica set commands | |
!!!rs.initiate() // NEVER run this except ONCE when you start your FIRST DB | |
// if one rs adds another machine with its own rs, | |
// it will wreck your life | |
rs.slaveOK() | |
rs.status() | |
var cfg = rs.config() // gets current replica set configuration | |
delete cfg.members[0].hidden // deletes a property from the configuration hash | |
rs.reconfig(cfg) // replaces current configuration with cfg |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment