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
我想从我的mongo数据库中找到一些文档,我正在使用函数:FindBy()不幸的是,这个函数没有任何字段选择参数,就像本机mongodb驱动程序对函数:find()具有的那样。有没有人知道如何在Mongodb的原则中选择自定义字段?谢谢
2 个解决方案
#1
5
You will need to use QueryBuilder with the select
operator:
您需要对select操作符使用QueryBuilder:
$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
#2
0
findBy does support operators, but the argument provided should be an array with the field name as key for the first dimension, like so :
findBy确实支持操作符,但提供的参数应该是一个数组,字段名作为第一个维度的键,如下所示:
$results = $yourRepositoryInstance->findBy(['somefield' => ['$in' => $arrayOfValues]]);
#1
5
You will need to use QueryBuilder with the select
operator:
您需要对select操作符使用QueryBuilder:
$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
#2
0
findBy does support operators, but the argument provided should be an array with the field name as key for the first dimension, like so :
findBy确实支持操作符,但提供的参数应该是一个数组,字段名作为第一个维度的键,如下所示:
$results = $yourRepositoryInstance->findBy(['somefield' => ['$in' => $arrayOfValues]]);