Skip to content

Commit a5e55c8

Browse files
committed
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
1 parent adcfd4e commit a5e55c8

File tree

3 files changed

+14
-10
lines changed

3 files changed

+14
-10
lines changed

README.md

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -117,10 +117,10 @@ And add a new mongodb connection:
117117
'host' => env('DB_HOST', 'localhost'),
118118
'port' => env('DB_PORT', 27017),
119119
'database' => env('DB_DATABASE', ''),
120+
'username' => env('DB_USERNAME', ''),
121+
'password' => env('DB_PASSWORD', ''),
120122
'options' => [
121-
'db' => 'admin', // sets the authentication database required by mongo 3
122-
'username' => env('DB_USERNAME', ''),
123-
'password' => env('DB_PASSWORD', ''),
123+
'db' => 'admin' // sets the authentication database required by mongo 3
124124
]
125125
],
126126
```
@@ -133,12 +133,9 @@ You can connect to multiple servers or replica sets with the following configura
133133
'host' => ['server1', 'server2'],
134134
'port' => env('DB_PORT', 27017),
135135
'database' => env('DB_DATABASE', ''),
136-
'options' => [
137-
'replicaSet' => 'replicaSetName',
138-
'db' => 'admin', // sets the authentication database required by mongo 3
139-
'username' => env('DB_USERNAME', ''),
140-
'password' => env('DB_PASSWORD', ''),
141-
]
136+
'username' => env('DB_USERNAME', ''),
137+
'password' => env('DB_PASSWORD', ''),
138+
'options' => ['replicaSet' => 'replicaSetName']
142139
],
143140
```
144141

src/Jenssegers/Mongodb/Connection.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,13 @@ protected function createConnection($dsn, array $config, array $options)
136136
$driverOptions = $config['driver_options'];
137137
}
138138

139+
if (!isset($options['username'])){
140+
$options['username'] = isset($config['username']) ? $config['username'] : '';
141+
}
142+
if (!isset($options['password'])){
143+
$options['password'] = isset($config['password']) ? $config['password'] : '';
144+
}
145+
139146
return new Client($dsn, $options, $driverOptions);
140147
}
141148

src/Jenssegers/Mongodb/Schema/Blueprint.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,7 @@ public function drop()
209209
* @param array $parameters
210210
* @return Blueprint
211211
*/
212-
protected function addColumn($type, $name, array $parameters = [])
212+
public function addColumn($type, $name, array $parameters = [])
213213
{
214214
$this->fluent($name);
215215

0 commit comments

Comments
 (0)