Skip to content

Commit

Permalink
- %help : overall help message
Browse files Browse the repository at this point in the history
- %help db : db method help message
* help message referred by mongodb shell help message.
  • Loading branch information
Bloodevil committed Sep 24, 2014
1 parent 15331bb commit 8c2cfa5
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 0 deletions.
46 changes: 46 additions & 0 deletions helps.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
DB_METHODS = """
db.addUser(userDocument)
db.adminCommand(nameOrDocument) - switches to 'admin' db, and runs command [ just calls db.runCommand(...) ]
db.auth(username, password)
db.cloneDatabase(fromhost)
db.commandHelp(name) returns the help for the command
db.copyDatabase(fromdb, todb, fromhost)
db.createCollection(name, { size : ..., capped : ..., max : ... } )
db.currentOp() displays currently executing operations in the db
db.dropDatabase()
db.eval(func, args) run code server-side
db.fsyncLock() flush data to disk and lock server for backups
db.fsyncUnlock() unlocks server following a db.fsyncLock()
db.getCollection(cname) same as db['cname'] or db.cname
db.getCollectionNames()
db.getLastError() - just returns the err msg string
db.getLastErrorObj() - return full status object
db.getMongo() get the server connection object
db.getMongo().setSlaveOk() allow queries on a replication slave server
db.getName()
db.getPrevError()
db.getProfilingLevel() - deprecated
db.getProfilingStatus() - returns if profiling is on and slow threshold
db.getReplicationInfo()
db.getSiblingDB(name) get the db at the same server as this one
db.hostInfo() get details about the server's host
db.isMaster() check replica primary status
db.killOp(opid) kills the current operation in the db
db.listCommands() lists all the db commands
db.loadServerScripts() loads all the scripts in db.system.js
db.logout()
db.printCollectionStats()
db.printReplicationInfo()
db.printShardingStatus()
db.printSlaveReplicationInfo()
db.removeUser(username)
db.repairDatabase()
db.resetError()
db.runCommand(cmdObj) run a database command. if cmdObj is a string, turns it into { cmdObj : 1 }
db.serverStatus()
db.setProfilingLevel(level,<slowms>) 0=off 1=slow 2=all
db.setVerboseShell(flag) display extra information in shell output
db.shutdownServer()
db.stats()
db.version() current version of the server
"""
16 changes: 16 additions & 0 deletions imongo.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from pymongo import MongoClient
from pymongo.database import Database
from IPython.core.magic import Magics, magics_class, line_cell_magic, line_magic
from helps import DB_METHODS

@magics_class
class MongoDB(Magics):
Expand Down Expand Up @@ -35,6 +36,21 @@ def show_collections(self, line):
collections = self.show_dbs(self)
return collections

@line_magic('help')
def help_message(self, line):
message = ''
if line == 'db':
message += DB_METHODS
else:
message += """
%help db help on db methods
%help collection help on collection methods
%show_dbs show database names
%show_collections show collections in current database
"""
print message

def load_ipython_extension(ipython):
ipython.register_magics(MongoDB)

0 comments on commit 8c2cfa5

Please sign in to comment.