think-orm
think-orm copied to clipboard
mongodb的dbName没有被用到,登录验证失败
public function connect(array $config = [], $linkNum = 0)
{
if (!isset($this->links[$linkNum])) {
if (empty($config)) {
$config = $this->config;
} else {
$config = array_merge($this->config, $config);
}
$this->dbName = $config['database'];
$this->typeMap = $config['type_map'];
if ($config['pk_convert_id'] && '_id' == $config['pk']) {
$this->config['pk'] = 'id';
}
if (empty($config['dsn'])) {
$config['dsn'] = 'mongodb://' . ($config['username'] ? "{$config['username']}" : '') . ($config['password'] ? ":{$config['password']}@" : '') . $config['hostname'] . ($config['hostport'] ? ":{$config['hostport']}" : '');
}
$startTime = microtime(true);
$this->links[$linkNum] = new Manager($config['dsn'], $config['params']);
if (!empty($config['trigger_sql'])) {
// 记录数据库连接信息
$this->trigger('CONNECT:[ UseTime:' . number_format(microtime(true) - $startTime, 6) . 's ] ' . $config['dsn']);
}
}
return $this->links[$linkNum];
}
config/database.php中mongo库配置信息增加params授权数据集,如下:
'mongo' => [
// 数据库类型
'type' => 'Mongo',
// 设置查询类
'query' => '\think\db\Mongo',
// 服务器地址
'hostname' => '192.168.1.xxx',
// 集合名
'database' => '集合名',
// 用户名
'username' => '账号',
// 密码
'password' => '密码',
// 端口
'hostport' => 27017,
'params' => [
'authSource' => '集合名',
],
],
config/database.php中mongo库配置信息增加params授权数据集,如下:
'mongo' => [
// 数据库类型
'type' => 'Mongo',
// 设置查询类
'query' => '\think\db\Mongo',
// 服务器地址
'hostname' => '192.168.1.xxx',
// 集合名
'database' => '集合名',
// 用户名
'username' => '账号',
// 密码
'password' => '密码',
// 端口
'hostport' => 27017,
'params' => [
'authSource' => '集合名',
],
],