【发布时间】:2018-12-19 19:18:08
【问题描述】:
我已经编写了下面的代码行,用于在查找中获取一些特定字段,例如
$pipeline = array(
array(
'$match' => $query
),
array(
'$lookup' => array(
'from' => 'studentTbl',
'localField' => '_id',
'foreignField' => 'activity_details.activityId',
'pipeline' => [
['$project' => [ '_id' => 1.0, 'activity_details' => 1.0] ],
],
'as' => 'studentsOfActivities'
)
),
....
....
);
return $this->db->activitiesTbl->aggregate($pipeline)->toArray();
基本上 studentTbl 有很多字段和嵌入的文档。在上面的代码中,我首先使用外部和本地字段通过查找来获取,然后确定应该将哪些字段投影到管道中。
上面的代码不工作...请帮助!!!
【问题讨论】:
-
activity_details是数组还是对象? -
它在一个数组中(studentTbl的嵌入文档)
标签: mongodb mongodb-query aggregation-framework mongodb-php php-mongodb