Cml\Db\MongoDB\MongoDB::runMongoCommand PHP Method

runMongoCommand() public method

执行命令
public runMongoCommand ( array $cmd = [], boolean $runOnMaster = true, boolean $returnCursor = false ) : array | MongoDB\Driver\Cursor
$cmd array 要执行的Command
$runOnMaster boolean 使用主库还是从库执行 默认使用主库执行
$returnCursor boolean 返回数据还是cursor 默认返回结果数据
return array | MongoDB\Driver\Cursor
    public function runMongoCommand($cmd = [], $runOnMaster = true, $returnCursor = false)
    {
        Cml::$debug && $this->debugLogSql('Command', '', $cmd);
        $this->reset();
        $db = $runOnMaster ? $this->getMaster()->selectServer(new ReadPreference(ReadPreference::RP_PRIMARY_PREFERRED)) : $this->getSlave()->selectServer(new ReadPreference(ReadPreference::RP_SECONDARY_PREFERRED));
        $cursor = $db->executeCommand($this->getDbName(), new Command($cmd));
        if ($returnCursor) {
            return $cursor;
        } else {
            $cursor->setTypeMap(['root' => 'array', 'document' => 'array']);
            $result = [];
            foreach ($cursor as $collection) {
                $result[] = $collection;
            }
            return $result;
        }
    }