php - Doctrine MongoDB - 使用 Doctrine MongoDB Aggregation Builder 在构面内水合结果
问题描述
我有以下查询,我希望第一个结果是水合的。这是我尝试过的:
$builder = $dm->createAggregationBuilder(\Documents\Jobs::class);
$builder
->facet()
->field('carpenterJobs')
->pipeline(
$dm->createAggregationBuilder(\Documents\Jobs::class)
->hydrate($this->getEntityName(\Documents\Jobs::class))
->match()
->field('name')
->equals('carpenter');
)
->field('cleanerJobs')
->pipeline(
$dm->createAggregationBuilder(\Documents\Jobs::class)
->match()
->field('name')
->equals('cleaner');
)
;
但是当我执行这个时,结果没有水合。下面是 Jobs 实体:
/**
* @QueryResultDocument
* @Document(repositoryClass="...")
*/
class Jobs
{
/**
* @Id
*/
private $id;
/**
* @Field(type="string")
* @Index(unique=true, order="asc")
*/
private $name;
...
}
我也尝试过水合,$builder
但它返回一个错误说Undefined index: _id
。自己执行 'carpenterJobs' 查询,无需在水龙头内,我可以返回水合结果。
解决方案
推荐阅读
- javascript - 无法连接到新的 MongoDB 社区版安装
- c++ - 重载 new 和 delete 的 nothrow 版本
- php - 错误 SQLSTATE [23505]:唯一违规:7 错误:当我尝试从 Laravel 进行一些注册时,重复键值违反了唯一约束
- php - PHP - PHPExcel Range to Array 忽略空列
- javascript - 如何通过调用编码函数获取智能合约的返回值
- javascript - JS 在原型上定义一个 getter 函数显示在对象本身上
- php - 显示自定义动态字段存储数据 woocommerce 订单管理和 meta 中的谢谢页面。?
- c - 指针作为参数接收
- javascript - 如何在 React Native 应用程序中预填充 TextInput?
- reactjs - 如何定义输入以在reactjs中保持浮点数