public function getIterator(): \Iterator
    {
        $hydrator = $this->documentManager->newHydrator($this->hydrationMode);
        $query = clone $this->query;

        if (! $query->hasParam('_source')) {
            /** @var DocumentMetadata $class */
            $class = $this->documentManager->getClassMetadata($this->documentClass);
            $query->setSource($class->eagerFieldNames);
        }

        if (null !== $this->sort) {
            $query->setSort($this->sort);
        }

        if (null !== $this->limit) {
            $query->setSize($this->limit);
        }

        if (null !== $this->offset) {
            $query->setFrom($this->offset);
        }

        $generator = null !== $this->cacheProfile ? $this->_doExecuteCached($query) : $this->_doExecute($query);
        foreach ($generator as $resultSet) {
            yield from $hydrator->hydrateAll($resultSet, $this->documentClass);
        }
    }