thinkphp5 mongodb Authentication failed 解决办法
Bulk write failed due to previous MongoDB\Driver\Exception\AuthenticationException: Authentication failed.
原因是 /vendor/topthink/think-mongo/src/Connection.php 文件中connect 方法(大概189行左右)在拼接dns的时候缺少参数
$config['dsn'] = 'mongodb://' . ($config['username'] ? "{$config['username']}" : '') . ($config['password'] ? ":{$config['password']}@" : '') . $config['hostname'] . ($config['hostport'] ? ":{$config['hostport']}" : '');
dns格式是mongodb://username:passwd@localhost:3306/DbName?param1=val1¶m2=val2#utf8 参数补齐就行了
$config['dsn'] = 'mongodb://' . ($config['username'] ? "{$config['username']}" : '') . ($config['password'] ? ":{$config['password']}@" : '') . $config['hostname'] . ($config['hostport'] ? ":{$config['hostport']}" : '') . "/" . $config['database'] ;
|