Skip to content

Commit bf4b479

Browse files
miguaoliu21st
authored andcommitted
fix(mongodb): 修复 DSN 构建时 authSource 参数缺失问题
1 parent 7ca8aab commit bf4b479

1 file changed

Lines changed: 3 additions & 0 deletions

File tree

src/db/connector/Mongo.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,8 @@ class Mongo extends Connection
6666
'username' => '',
6767
// 密码
6868
'password' => '',
69+
// 验证数据库
70+
'auth_source' => '',
6971
// 端口
7072
'hostport' => '',
7173
// 连接dsn
@@ -169,6 +171,7 @@ public function connect(array $config = [], $linkNum = 0)
169171

170172
if (empty($config['dsn'])) {
171173
$config['dsn'] = 'mongodb://' . ($config['username'] ? "{$config['username']}" : '') . ($config['password'] ? ":{$config['password']}@" : '') . $config['hostname'] . ($config['hostport'] ? ":{$config['hostport']}" : '');
174+
$config['dsn'] .= !empty($config['auth_source']) ? '/?authSource=' . $config['auth_source'] : '';
172175
}
173176

174177
$startTime = microtime(true);

0 commit comments

Comments
 (0)