Skip to content

Instantly share code, notes, and snippets.

@svetlyak40wt
Created June 26, 2012 07:02
Show Gist options
  • Save svetlyak40wt/2993954 to your computer and use it in GitHub Desktop.
Save svetlyak40wt/2993954 to your computer and use it in GitHub Desktop.
./manage.py dbshell for Flask + MongoDB
import subprocess
import myproject
from flaskext.script import Manager
manager = Manager(app)
@manager.command
def dbshell():
db = myproject.get_db()
result = db.connection.admin.command({'isMaster': 1})
host, port = result['primary'].split(':')
subprocess.call('mongo --host "{host}" --port "{port}" "{db.name}"'.format(**locals()), shell=True)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment