Created
June 26, 2012 07:02
-
-
Save svetlyak40wt/2993954 to your computer and use it in GitHub Desktop.
./manage.py dbshell for Flask + MongoDB
This file contains 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
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