Created
December 15, 2015 01:29
-
-
Save jlai/9d1097fdadba7b86ccfa to your computer and use it in GitHub Desktop.
Create mongo shell command from mongo connection uri
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
#!/usr/bin/env python | |
import sys | |
import urlparse | |
if len(sys.argv) < 2: | |
print("usage: " + sys.argv[0] + " <uri>") | |
sys.exit(1) | |
uri = sys.argv[1] | |
parts = urlparse.urlparse(uri) | |
hosts = parts.netloc.split('@')[-1].split(',') | |
for host in hosts: | |
args = ["mongo", "-u", parts.username, "-p", parts.password, host + parts.path] | |
print(" ".join(args)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment