3

I have the following problem: I can't limit number of results when using distinct. Exemple :

$stores = $this->dm->createQueryBuilder('Application\Document\Item')
   ->distinct('storeName')
   ->limit(10)
   ->getQuery()
   ->execute();

This query render 100 entries but I want only 10 results.

Siol
  • 311
  • 8
  • 21

2 Answers2

1

With query builder class in ORM you need to use:

->setMaxResults(10);

As per @Siol and @john Smith said, in ODM you could use limit:

->limit(10);
manix
  • 14,537
  • 11
  • 70
  • 107
0

I don't think distinct will work with limit as suggested in the Jira mongodb issue ticket Ability to use Limit() with Distinct():

The current Distinct() implementation only allows for bringing back ALL distinct values in the collection or matching a query, but there is no way to limit these results. This would be very convenient and there are many use cases.