Add credentials to parameters

- Adding the credentials via dsn causes problems when the password contains an @ symbol
parent b2e8833c
...@@ -136,6 +136,9 @@ class Connection extends \Illuminate\Database\Connection ...@@ -136,6 +136,9 @@ class Connection extends \Illuminate\Database\Connection
$driverOptions = $config['driver_options']; $driverOptions = $config['driver_options'];
} }
$options['username'] = $config['username'];
$options['password'] = $config['password'];
return new Client($dsn, $options, $driverOptions); return new Client($dsn, $options, $driverOptions);
} }
...@@ -175,20 +178,7 @@ class Connection extends \Illuminate\Database\Connection ...@@ -175,20 +178,7 @@ class Connection extends \Illuminate\Database\Connection
} }
} }
// The database name needs to be in the connection string, otherwise it will return "mongodb://" . implode(',', $hosts) . "/{$database}";
// authenticate to the admin database, which may result in permission errors.
$auth = '';
if (! empty($username)) {
$auth .= $username;
}
if (! empty($password)) {
$auth .= ':' . urlencode($password);
}
if ($auth) {
$auth .= '@';
}
return "mongodb://" . $auth . implode(',', $hosts) . "/{$database}";
} }
/** /**
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment