Commit b1ed1667 authored by Steve Porter's avatar Steve Porter

refactor: support dsn strings with and without mongodb prefix

parent c3b622ab
...@@ -4,6 +4,7 @@ namespace Jenssegers\Mongodb; ...@@ -4,6 +4,7 @@ namespace Jenssegers\Mongodb;
use Illuminate\Database\Connection as BaseConnection; use Illuminate\Database\Connection as BaseConnection;
use Illuminate\Support\Arr; use Illuminate\Support\Arr;
use Illuminate\Support\Str;
use MongoDB\Client; use MongoDB\Client;
class Connection extends BaseConnection class Connection extends BaseConnection
...@@ -168,9 +169,15 @@ class Connection extends BaseConnection ...@@ -168,9 +169,15 @@ class Connection extends BaseConnection
*/ */
protected function getDsnString(array $config) protected function getDsnString(array $config)
{ {
$dsn = rawurlencode($config['dsn']); $dsn_string = $config['dsn'];
return "mongodb://{$dsn}"; if ( Str::contains($dsn_string, 'mongodb://') ){
$dsn_string = Str::replaceFirst('mongodb://', '', $dsn_string);
}
$dsn_string = rawurlencode($dsn_string);
return "mongodb://{$dsn_string}";
} }
/** /**
......
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