yii\mongodb\BatchQueryResult::fetchData PHP Method

fetchData() protected method

Fetches the next batch of data.
protected fetchData ( ) : array
return array the data fetched
    protected function fetchData()
    {
        if ($this->_iterator === null) {
            if (empty($this->query->orderBy)) {
                // setting cursor batch size may setup implicit limit on the query with 'sort'
                // @see https://jira.mongodb.org/browse/PHP-457
                $this->query->addOptions(['batchSize' => $this->batchSize]);
            }
            $cursor = $this->query->buildCursor($this->db);
            $token = 'fetch cursor id = ' . $cursor->getId();
            Yii::info($token, __METHOD__);
            if ($cursor instanceof \Iterator) {
                $this->_iterator = $cursor;
            } else {
                $this->_iterator = new \IteratorIterator($cursor);
            }
            $this->_iterator->rewind();
        }
        $rows = [];
        $count = 0;
        while ($count++ < $this->batchSize) {
            $row = $this->_iterator->current();
            if ($row === null) {
                break;
            }
            $this->_iterator->next();
            //var_dump($row);
            $rows[] = $row;
        }
        return $this->query->populate($rows);
    }