/** * @param \MongoDB\Driver\Cursor $cursor Mongo cursor instance to fetch data from. * @param bool $all whether to fetch all rows or only first one. * @return array|bool result. * @see Query::fetchRows() */ protected function fetchRowsInternal($cursor, $all) { $result = []; if ($all) { foreach ($cursor as $row) { $result[] = $row; } } else { if ($row = current($cursor->toArray())) { $result = $row; } else { $result = false; } } return $result; }