Tp5连接MongoDB报:Authentication failed解决方案
PHP的MongoDB扩展:MongoDB 1.4.1
报错信息:Authentication failed
原因
tp5 think-mongo扩展 当使用普通用户连接数据库时会报:Authentication failed(认证失败),原因是 think-mongo扩展连接数据库认证的时候没有带上数据库名!
连接串为:mongodb://{username}:{password}@{hostname}:{hostport}
应改为:mongodb://{username}:{password}@{hostname}:{hostport}/{dbName}
修改方式
/vendor/topthink/think-mongo/src/connection.php
中的第152行
// 在这段代码的最后加上 ."/".$this->dbName;
$host = 'mongodb://' . ($config['username'] ? "{
$config['username']}" : '') . (