(server, sanitize_username=False)
return username, password, db_name, nodelist, clean_server_name, auth_source
Parses a MongoDB-formatted URI (e.g. mongodb://user:pass@server/db) and returns parsed elements
    and a sanitized URI.
Parses a MongoDB-formatted URI (e.g. mongodb://user:pass
Parses a MongoDB - formatted URI ( e . g . mongodb : // user : pass
def parse_mongo_uri(server, sanitize_username=False):
    """
    Parses a MongoDB-formatted URI (e.g. mongodb://user:pass@server/db) and returns parsed elements
    and a sanitized URI.
    """
    parsed = pymongo.uri_parser.parse_uri(server)

    username = parsed.get('username')
    password = parsed.get('password')
    db_name = parsed.get('database')
    nodelist = parsed.get('nodelist')
    auth_source = parsed.get('options', {}).get('authsource') or db_name or "admin"

    # Remove password (and optionally username) from sanitized server URI.
    # To ensure that the `replace` works well, we first need to url-decode the raw server string
    # since the password parsed by pymongo is url-decoded
    decoded_server = unquote_plus(server)
    clean_server_name = decoded_server.replace(password, "*" * 5) if password else decoded_server

    if sanitize_username and username:
        username_pattern = u"{}[@:]".format(re.escape(username))
        clean_server_name = re.sub(username_pattern, "", clean_server_name)

    return username, password, db_name, nodelist, clean_server_name, auth_source
def parse_mongo_uri ( server , sanitize_username = False ) : parsed = pymongo . uri_parser . parse_uri ( server ) username = parsed . get ( 'username' ) password = parsed . get ( 'password' ) db_name = parsed . get ( 'database' ) nodelist = parsed . get ( 'nodelist' ) auth_source = parsed . get ( 'options' , { } ) . get ( 'authsource' ) or db_name or "admin" # Remove password (and optionally username) from sanitized server URI. # To ensure that the `replace` works well, we first need to url-decode the raw server string # since the password parsed by pymongo is url-decoded decoded_server = unquote_plus ( server ) clean_server_name = decoded_server . replace ( password , "*" * 5 ) if password else decoded_server if sanitize_username and username : username_pattern = u"{}[@:]" . format ( re . escape ( username ) ) clean_server_name = re . sub ( username_pattern , "" , clean_server_name ) return username , password , db_name , nodelist , clean_server_name , auth_source