Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to select certain fields with mongodb doctrine in symfony2

I want to find some documents from my mongo Database, and I'm using the function : FindBy() unfortunately this function doesn't have any field selection arguments like native mongodb driver has with the function : find(). Does any one know how to select custom fields in the doctrine of Mongodb ? Thanks

like image 663
Aysennoussi Avatar asked Jan 03 '14 10:01

Aysennoussi


1 Answers

You will need to use QueryBuilder with the select operator:

$result = $dm->createQueryBuilder('User')->select('field1', 'field2')->field('field3')->equals('somevalue')->getQuery()->execute();

http://docs.doctrine-project.org/projects/doctrine-mongodb-odm/en/latest/reference/query-builder-api.html

like image 122
dylan oliver Avatar answered Sep 17 '22 17:09

dylan oliver