11

I am doing a query on a result document in my doctrine mongodb *odm*. There are two indexed fields in the document which I would like to use in sort. I have written something like:

$results = $this->createQueryBuilder('Document\Score')
            ->sort('finalScore', 'desc')
            ->sort('date', 'desc')
            ->getQuery()
            ->execute();

Here the second sort() function overrides the first one and the designated result is never found.

Thanks in advance for the nice help.

Himel Nag Rana
  • 744
  • 1
  • 11
  • 19

1 Answers1

16

Try this

$qb = $this->createQueryBuilder('Document\Score');
$qb->sort(array(
    'finalScore' => 'desc',
    'date'       => 'desc',
));
$results = $qb->getQuery()->execute();
AdrienBrault
  • 7,747
  • 4
  • 31
  • 42