聚合连接在mongo db中不起作用

时间:2017-08-16 11:14:23

标签: mongodb mongodb-query aggregation-framework php-mongodb

我有三个跟随领域的集合

  • productTbl

    - productId

    - productName

    - categoryId

    - vendorId

    ....等等

  • categoryTbl

    - categoryId

    - categoryName

  • VendorTbl

    - VendorID

    - VendorName

我在下面写了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); 

现在上面的查询从product表中获取所有的feild,但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",
           ...
           ...
         }

0 个答案:

没有答案
相关问题