Siol
Siol

Reputation: 411

Doctrine ODM Distinct With Limit

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.

Upvotes: 3

Views: 3024

Answers (2)

Sudheesh S Babu
Sudheesh S Babu

Reputation: 91

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.

Upvotes: 0

manix
manix

Reputation: 14747

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);

Upvotes: 1

Related Questions