如何在MongoDB中以主条件联接主明细表

时间:2019-01-18 09:19:13

标签: mongodb join aggregate where lookup

如何为xads这个查询添加条件? (Exp:lads.status = 1)

db.xads.aggregate([
                {
                    $lookup: {
                        from: 'xaditems',
                        localField: '_id',
                        foreignField: 'masterId',
                        as: 'xadItems'
                    },
                }
              ]);

2 个答案:

答案 0 :(得分:0)

db.xads.aggregate([
                {
                 $match:{"status":1} //add you filters in match
                },
                {
                    $lookup: {
                        from: 'xaditems',
                        localField: '_id',
                        foreignField: 'masterId',
                        as: 'xadItems'
                    },
                }
              ]);

答案 1 :(得分:0)

行!谢谢DHIRAJ KATEKAR

db.xads.aggregate([
                {
                 $match:{"status":1} 
                },
                {
                    $lookup: {
                        from: 'xaditems',
                        localField: '_id',
                        foreignField: 'masterId',
                        as: 'xadItems'
                    },
                }
              ]);