Skip to content

Commit b1ed166

Browse files
author
Steve Porter
committed
refactor: support dsn strings with and without mongodb prefix
1 parent c3b622a commit b1ed166

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

src/Jenssegers/Mongodb/Connection.php

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
use Illuminate\Database\Connection as BaseConnection;
66
use Illuminate\Support\Arr;
7+
use Illuminate\Support\Str;
78
use MongoDB\Client;
89

910
class Connection extends BaseConnection
@@ -168,9 +169,15 @@ protected function hasDsnString(array $config)
168169
*/
169170
protected function getDsnString(array $config)
170171
{
171-
$dsn = rawurlencode($config['dsn']);
172-
173-
return "mongodb://{$dsn}";
172+
$dsn_string = $config['dsn'];
173+
174+
if ( Str::contains($dsn_string, 'mongodb://') ){
175+
$dsn_string = Str::replaceFirst('mongodb://', '', $dsn_string);
176+
}
177+
178+
$dsn_string = rawurlencode($dsn_string);
179+
180+
return "mongodb://{$dsn_string}";
174181
}
175182

176183
/**

0 commit comments

Comments
 (0)