Cml\Db\MongoDB\MongoDB::runMongoQuery PHP Method

runMongoQuery() public method

执行mongoQuery命令
public runMongoQuery ( string $tableName, array $condition = [], array $queryOptions = [], boolean | string $useMaster = false ) : array
$tableName string 执行的mongoCollection名称
$condition array 查询条件
$queryOptions array 查询的参数
$useMaster boolean | string 是否使用主库
return array
    public function runMongoQuery($tableName, $condition = [], $queryOptions = [], $useMaster = false)
    {
        Cml::$debug && $this->debugLogSql('Query', $tableName, $condition, $queryOptions);
        $this->reset();
        $db = $useMaster ? $this->getMaster()->selectServer(new ReadPreference(ReadPreference::RP_PRIMARY_PREFERRED)) : $this->getSlave()->selectServer(new ReadPreference(ReadPreference::RP_SECONDARY_PREFERRED));
        $cursor = $db->executeQuery($this->getDbName() . ".{$tableName}", new Query($condition, $queryOptions));
        $cursor->setTypeMap(['root' => 'array', 'document' => 'array']);
        $result = [];
        foreach ($cursor as $collection) {
            $result[] = $collection;
        }
        return $result;
    }