2016-04-29 189 views
-4
product[{ 
    "_id" : ObjectId("5720cc7d6e589904b855cc12"), 
    "p_id" : "p0001", 
    "p_name" : "printed_pant", 
    "p_company" : "Hoffman", 
    "p_price" : 3677.0, 
    "p_color" : "charcol", 
    "p_size" : "XL", 
    "total_price" : 77217.0, 
    "total_sell" : NumberInt(21) 
}] 

branch[{ 
    "_id" : { 
     "c_branch_id" : "b03", 
     "c_branch_location" : "Hydrabad", 
     "p_id" : "p0001", 
     "p_name" : "kurty_pajam" 
    }, 

    "total_item" : NumberInt(8) 
}] 

我怎么能在上面提到的集合中使用$lookup? 其中product是leftcollection,branch是rightcollection。

回答

0

像这样的东西?

db.product.aggregate([ 
    { 
     $lookup: 
     { 
      from: "branch", 
      localField: "p_id", 
      foreignField: "_id.p_id", 
      as: "branch_docs" 
     } 
    } 
]) 
+0

是的,我想这一点,但它不工作.. –

+0

@BiswajitMaity这是为什么'foreignField: “_id的p_id”'(空格) – Max

+0

谢谢@Max ......它的工作... –