首页 > 解决方案 > 如何在 MongoDB 中加入具有主条件的主从表

问题描述

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

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

标签: mongodbjoinaggregatewherelookup

解决方案


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

推荐阅读