Add credentials to MongoDB constructor

- Reverted the config changes
- The credentials are now added to the MongoDB constructor if they are not already present
- Also fixed failing test by changing method access level
parent 38c91036
...@@ -117,10 +117,10 @@ And add a new mongodb connection: ...@@ -117,10 +117,10 @@ And add a new mongodb connection:
'host' => env('DB_HOST', 'localhost'), 'host' => env('DB_HOST', 'localhost'),
'port' => env('DB_PORT', 27017), 'port' => env('DB_PORT', 27017),
'database' => env('DB_DATABASE', ''), 'database' => env('DB_DATABASE', ''),
'options' => [
'db' => 'admin', // sets the authentication database required by mongo 3
'username' => env('DB_USERNAME', ''), 'username' => env('DB_USERNAME', ''),
'password' => env('DB_PASSWORD', ''), 'password' => env('DB_PASSWORD', ''),
'options' => [
'db' => 'admin' // sets the authentication database required by mongo 3
] ]
], ],
``` ```
...@@ -133,12 +133,9 @@ You can connect to multiple servers or replica sets with the following configura ...@@ -133,12 +133,9 @@ You can connect to multiple servers or replica sets with the following configura
'host' => ['server1', 'server2'], 'host' => ['server1', 'server2'],
'port' => env('DB_PORT', 27017), 'port' => env('DB_PORT', 27017),
'database' => env('DB_DATABASE', ''), 'database' => env('DB_DATABASE', ''),
'options' => [
'replicaSet' => 'replicaSetName',
'db' => 'admin', // sets the authentication database required by mongo 3
'username' => env('DB_USERNAME', ''), 'username' => env('DB_USERNAME', ''),
'password' => env('DB_PASSWORD', ''), 'password' => env('DB_PASSWORD', ''),
] 'options' => ['replicaSet' => 'replicaSetName']
], ],
``` ```
......
...@@ -136,6 +136,13 @@ class Connection extends \Illuminate\Database\Connection ...@@ -136,6 +136,13 @@ class Connection extends \Illuminate\Database\Connection
$driverOptions = $config['driver_options']; $driverOptions = $config['driver_options'];
} }
if (!isset($options['username'])){
$options['username'] = isset($config['username']) ? $config['username'] : '';
}
if (!isset($options['password'])){
$options['password'] = isset($config['password']) ? $config['password'] : '';
}
return new Client($dsn, $options, $driverOptions); return new Client($dsn, $options, $driverOptions);
} }
......
...@@ -209,7 +209,7 @@ class Blueprint extends \Illuminate\Database\Schema\Blueprint ...@@ -209,7 +209,7 @@ class Blueprint extends \Illuminate\Database\Schema\Blueprint
* @param array $parameters * @param array $parameters
* @return Blueprint * @return Blueprint
*/ */
protected function addColumn($type, $name, array $parameters = []) public function addColumn($type, $name, array $parameters = [])
{ {
$this->fluent($name); $this->fluent($name);
......
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