2017-04-03 128 views

回答

1

看看$lookup,在那裏你可以有點join兩個集合

db.product.aggregate(
{ 
    $lookup: { 
    from: 'category', 
    localField: 'categoryRef', 
    foreignField: 'catId', 
    as: 'category' 
    }, 
    {$unwind: '$category'}, 
    {$match: {'category.name': "testCat"}} 
}) 
+0

查找查找^^ –

+0

返回空數組.... –

+0

我發現的方式,但它不到風度工作,它會填充每個產品與所有類別... –