diff --git a/src/Jenssegers/Mongodb/Connection.php b/src/Jenssegers/Mongodb/Connection.php index 634e8faab..f7eca2e5a 100644 --- a/src/Jenssegers/Mongodb/Connection.php +++ b/src/Jenssegers/Mongodb/Connection.php @@ -136,6 +136,14 @@ protected function createConnection($dsn, array $config, array $options) $driverOptions = $config['driver_options']; } + // Check if the credentials are not already set in the options + if (!isset($options['username']) && isset($config['username'])) { + $options['username'] = $config['username']; + } + if (!isset($options['password']) && isset($config['password'])) { + $options['password'] = $config['password']; + } + return new Client($dsn, $options, $driverOptions); } @@ -175,20 +183,7 @@ protected function getDsn(array $config) } } - // The database name needs to be in the connection string, otherwise it will - // 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}"; + return "mongodb://" . implode(',', $hosts) . "/{$database}"; } /** diff --git a/src/Jenssegers/Mongodb/Schema/Blueprint.php b/src/Jenssegers/Mongodb/Schema/Blueprint.php index 3b4053ca9..144675b39 100644 --- a/src/Jenssegers/Mongodb/Schema/Blueprint.php +++ b/src/Jenssegers/Mongodb/Schema/Blueprint.php @@ -209,7 +209,7 @@ public function drop() * @param array $parameters * @return Blueprint */ - protected function addColumn($type, $name, array $parameters = []) + public function addColumn($type, $name, array $parameters = []) { $this->fluent($name);