我有以下三个系列
产品表
-- 产品标识
- 产品名称
-- 类别标识
-- 供应商 ID
.... 很快
类别表
-- 类别标识
- 分类名称
供应商表
-- 供应商ID
- 供应商名称
我在下面写了 mongodb 聚合查找查询
$pipeline = array(
array(
'$lookup' => array(
'from' => 'VendorTbl',
'localField' => 'vendorId',
'foreignField' => 'VendorID',
'as' => 'vendordetails'
)
),
array(
'$lookup' => array(
'from' => 'categoryTbl',
'localField' => 'categoryId',
'foreignField' => 'categoryId',
'as' => 'categorydetails'
)
),
);
$output = $this->db->productTbl->aggregate($pipeline);
现在上面的查询正在从产品表中获取所有字段,但是 categorydetails 和 vendordetails 是空的。我无法追踪这个问题。请帮忙!!!
输出就像
{"$id":"59941ea11d78596801000029"},"productId":14,"productName":"Pencils","vendorId":"2","categoryId":"5","quantity":"122","sellingPrice":"122","vendordetails":[],"categorydetails":[]
类别表的实际文档就像
{
"categoryId": 18,
"categoryName": "swdgvqaedeadsgsgdf",
}
供应商表的实际文件就像
{
"_id": ObjectId("599413e01d78596409000029"),
"VendorID": 3,
"VendorName": "hydfyugjgfu",
}
产品表的实际文档就像
{
"_id": ObjectId("59941ec11d7859680100002a"),
"productId": 15,
"productName": "Pens",
"vendorId": "3",
"categoryId": "7",
...
...
}