Skip to content

Commit 400f7b6

Browse files
committed
Fixed the connection string for master slave mongo db set up
1 parent 2760d04 commit 400f7b6

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

src/Jenssegers/Mongodb/Connection.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -111,20 +111,20 @@ protected function getDsn(array $config)
111111
// Treat host option as array of hosts
112112
$hosts = is_array($config['host']) ? $config['host'] : array($config['host']);
113113

114-
foreach ($hosts as &$host)
114+
if (isset($config['username']) and isset($config['password']))
115115
{
116-
if (isset($config['username']) and isset($config['password']))
117-
{
118-
$host = "{$username}:{$password}@{$host}";
119-
}
116+
$credentials = "{$username}:{$password}@";
117+
}
120118

119+
foreach ($hosts as &$host)
120+
{
121121
if (isset($config['port']))
122122
{
123123
$host = "{$host}:{$port}";
124124
}
125125
}
126126

127-
return "mongodb://" . implode(',', $hosts) . "/{$database}";
127+
echo "mongodb://" . $credentials . implode(',', $hosts) . "/{$database}";
128128
}
129129

130130
/**

0 commit comments

Comments
 (0)