Think/Db/Driver/Mongo.php
public function switchCollection($collection, $db = '', $master = true)
    {
        // 当前没有连接 则首先进行数据库连接
        if (!$this->_linkID) {
            $this->initConnect($master);
        }
        try {
            if (!empty($db)) {
                // 传入Db则切换数据库
                // 当前MongoDb对象
                $this->_dbName = $db;
                $this->_mongo = $this->_linkID->selectDb($db);
            }
            // 当前MongoCollection对象
            if ($this->config['debug']) {
                $this->queryStr = $this->_dbName.'.getCollection('.$collection.')';
            }
            if ($this->_collectionName != $collection) {
                $this->queryTimes++;
                $this->debug(true);
                $this->_collection = $this->_mongo->selectCollection($collection);
                $this->debug(false);
                // 记录当前Collection名称
                $this->_collectionName = $collection;
            }
        } catch (\MongoException $e) {
            E($e->getMessage());
        }
    }
public function switchCollection($collection, $db = '', $master = true)
    {
        // 当前没有连接 则首先进行数据库连接
        if (!$this->_linkID) {
            $this->initConnect($master);
        }
        try {
            if (!empty($db)) {
                // 传入Db则切换数据库
                // 当前MongoDb对象
                $this->_dbName = $db;
                $this->_mongo = $this->_linkID->selectDb($db);
            }
            // 当前MongoCollection对象
            if ($this->config['debug']) {
                $this->queryStr = $this->_dbName.'.getCollection('.$collection.')';
            }
            if ($this->_collectionName != $collection) {
                $this->queryTimes++;
                $this->debug(true);
                $this->_collection = $this->_mongo->selectCollection($collection);
                $this->debug(false);
                // 记录当前Collection名称
                $this->_collectionName = $collection;
            }
        } catch (\MongoException $e) {
            E($e->getMessage());
        }
    }
切换当前操作的Db和Collection
@param string $collection collection
@param string $db db
@param boolean $master 是否主服务器
@return void