我使用的是thinkphp6,mongodb4.0实际业务查询
$list = Db::connect('tstd_mongo')
->table("$table_time.Item")
->where($where)
->order("Cause","asc")
->field('_id,DBID,Data,GSID,MainKind,ManID,DISTINCT(Serial) Serial,SubKind,Time')
->paginate($limit);
->table("$table_time.Item")
我是根据数据,要去不同的数据库查询,需要修改源码
topthink\think-orm\src\db\connector\Mogo.php function command()下 ,
$dbName = $dbName ?: $this->dbName;
修改成
if (!empty($this->builder->dbName)){
$dbName = $dbName ?: $this->builder->dbName;
$this->dbName=$dbName;
}else{
$dbName = $dbName ?: $this->dbName;
}
如果使用paginate count 就要修改
topthink\think-orm\src\db\builder\Mongo.php
if (strstr($options['table'], '.')!== false) {
$parts = explode('.',$options['table']);
$count_db = !empty($parts[0])?$parts[0]:'';
$count_table = !empty($parts[1])?$parts[1]:'';
if (!empty($count_table)){
$options['table']=$count_table;
}
if (!empty($count_db)){
$this->dbName = $count_db;
}
}
如果用 其他 ,aggregate,select 方法 也要加这段代码