Reputation: 147
I am using Mongodb with Symfony. I have a list of building with rooms, how can I count the rooms in my db and group them by type? at the moment I can list all rooms type but some of them are duplicated. I saw lenght function but it seems that it counts the caracters not the number of rooms. Here is the query to fecth data :
$room= $this->get('doctrine_mongodb')
->getManager()
->createQueryBuilder(\Pms\PmsBundle\Document\Hotel\hotels::class)
->find()
->getQuery()
->execute();
Here is the code I am using to display room types :
{% for j in i.rooms %}
{% if j.roomfloor < 6 %}
{{ j.roomtype }}
{% endif %}
{% endfor %}
Upvotes: 0
Views: 304
Reputation: 4731
This is a work for your ORM not for Twig. Group By into your queryBuilder with a count and only after present your data into Twig.
Upvotes: 1