Reputation: 3860
I'm trying to find documents using Regex in Mongodb but I also want to select fields to be returned : My code is
$dm = $this->get('doctrine_mongodb')
->getManager();
$qb = $dm->createQueryBuilder('ngNearBundle:Users')->select('lat,lng,title,photos,description');
$titles=$qb->field('title')->equals(new \MongoRegex('/.*'.$key_words.'.*/i'))->getQuery()->execute()->toArray();
But the query returns an array with documents but all fields are NULL (All fields are returned and not only the selected ones! )
Upvotes: 0
Views: 72
Reputation: 4288
The select() call syntax is as follows :
$qb = $dm->createQueryBuilder('ngNearBundle:Users')
->select('lat','lng','title','photos','description');
Fields have to be distinct arguments at the php method level.
Upvotes: 1