Skip to content

Instantly share code, notes, and snippets.

@jlai
Created December 15, 2015 01:29
Show Gist options
  • Save jlai/9d1097fdadba7b86ccfa to your computer and use it in GitHub Desktop.
Save jlai/9d1097fdadba7b86ccfa to your computer and use it in GitHub Desktop.
Create mongo shell command from mongo connection uri
#!/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