/** * @return array */ protected function getIterationInfo() { $iterationInfo = ['started_iterating' => $this->cursor !== null]; if ($this->cursor !== null) { switch ($this->cursor->getServer()->getType()) { case \MongoDB\Driver\Server::TYPE_RS_ARBITER: $typeString = 'ARBITER'; break; case \MongoDB\Driver\Server::TYPE_MONGOS: $typeString = 'MONGOS'; break; case \MongoDB\Driver\Server::TYPE_RS_PRIMARY: $typeString = 'PRIMARY'; break; case \MongoDB\Driver\Server::TYPE_RS_SECONDARY: $typeString = 'SECONDARY'; break; default: $typeString = 'STANDALONE'; } $cursorId = (string) $this->cursor->getId(); $iterationInfo += ['id' => (int) $cursorId, 'at' => $this->position, 'numReturned' => $this->position, 'server' => sprintf('%s:%d;-;.;%d', $this->cursor->getServer()->getHost(), $this->cursor->getServer()->getPort(), getmypid()), 'host' => $this->cursor->getServer()->getHost(), 'port' => $this->cursor->getServer()->getPort(), 'connection_type_desc' => $typeString]; } return $iterationInfo; }
/** * Fetches rows from the given Mongo cursor. * @param \MongoDB\Driver\Cursor $cursor Mongo cursor instance to fetch data from. * @param bool $all whether to fetch all rows or only first one. * @param string|callable $indexBy the column name or PHP callback, * by which the query results should be indexed by. * @throws Exception on failure. * @return array|bool result. */ protected function fetchRows($cursor, $all = true, $indexBy = null) { $token = 'fetch cursor id = ' . $cursor->getId(); Yii::info($token, __METHOD__); try { Yii::beginProfile($token, __METHOD__); $result = $this->fetchRowsInternal($cursor, $all); Yii::endProfile($token, __METHOD__); return $result; } catch (\Exception $e) { Yii::endProfile($token, __METHOD__); throw new Exception($e->getMessage(), (int) $e->getCode(), $e); } }