PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Thursday, January 20, 2022

[FIXED] How to select certain fields with mongodb doctrine in symfony2

 January 20, 2022     doctrine, doctrine-orm, mongodb, php, symfony     No comments   

Issue

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


Solution

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



Answered By - dylan oliver
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing