[英]Doctrine ODM: get array of specific fields
So, the problem is to get ids (or any another fields) in one array, like: 因此,问题是要在一个数组中获取ID(或其他任何字段),例如:
[
"someId1",
"someId2",
"someId3",
]
I tried to take it by next query: 我试图通过下一个查询:
$this->createQueryBuilder()
->select('_id')
->hydrate(false)
->getQuery()
->toArray()
but I took not what I want, but near this: 但我没有拿走我想要的东西,而是走近了:
112 => array:1 [
"_id" => 112
]
113 => array:1 [
"_id" => 113
]
114 => array:1 [
"_id" => 114
]
(I use strategy INCREMENT). (我使用策略INCREMENT)。 I tried do this by map, reduce, but I understood that I know nothing in these functions :).
我尝试通过map,reduce来做到这一点,但我知道我对这些功能一无所知:)。 So can somebody help me?
那有人可以帮我吗?
PS: I know how to realise this with php functions, like array_keys | array_values
PS:我知道如何使用php函数来实现这一点,例如
array_keys | array_values
array_keys | array_values
. array_keys | array_values
。 But I really want to know how to do it by mongoDB, and particularly, in ODM with createQueryBuilder 但是我真的很想知道如何通过mongoDB做到这一点,尤其是在带有createQueryBuilder的ODM中
This usually can be done by creating a custom hydrator. 通常可以通过创建自定义水化器来完成。 You could take a look at this example and try to adapt it to ODM https://gist.github.com/Tom32i/7984541
您可以看一下此示例,然后尝试使其适应ODM https://gist.github.com/Tom32i/7984541
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.