Order in Doctrine ODM queryBuilder with preference of fields

23 Views Asked by At

I am using Doctrine ODM to make queries to a MongoDB with queryBuilder API.

I would like to know if it is possible to order the result of a query, so that if a condition is met, they are put before.

In sql it would be something like this.

SELECT id, sport, city
FROM matches
ORDER BY
    CASE
        WHEN sport= 'Football' THEN 1
        WHEN city= 'London' THEN 2
        ELSE 3
    END,
    date;

But I don't know how to do it with queryBuilder.

0

There are 0 best solutions below