config中的database.php中加入
# 数据库配置2
'db_config2' =>[
// 数据库类型
'type' => '\think\mongo\Connection',
// 设置查询类
'query' => '\think\mongo\Query',
// 服务器地址
'hostname' => '127.0.0.1',
// 集合名
'database' => 'leegame_chat',
// 用户名
'username' => '',
// 密码
'password' => '',
// 端口
'hostport' => '27017',
// 强制把_id转换为id
'pk_convert_id' => true,
],
控制器方法中直接使用
$test1=Db::connect("db_config2")->name("leegame")->select();