Learn about the paginator on Zend Framework Paginator documentation.
use Zend\Paginator\Paginator;
use ZendPaginatorAdapter\DoctrineMongoDBAdapter;
$query = $repository->createQuery(); // create a Doctrine MongoDB Query
$adapter = new DoctrineMongoDBAdapter($query); // create a Doctrine MongoDB Adapter
$paginator = new Paginator($adapter); // create a Paginator
use Zend\Paginator\Paginator;
use ZendPaginatorAdapter\DoctrineORMAdapter;
$query = $repository->createQuery(); // create a Doctrine ORM Query
$adapter = new DoctrineORMAdapter($query); // create a Doctrine ORM Adapter
$paginator = new Paginator($adapter); // create a Paginator