鍍金池/ 問答/數(shù)據(jù)庫  HTML/ mongoose多表模糊查詢

mongoose多表模糊查詢

this.find({}).populate({
            path: 'userId',
            match: {name: '123123x'}
        }).exec(callback);

兩張表的關聯(lián)查詢,關聯(lián)表沒有數(shù)據(jù)當時候怎么讓整條數(shù)據(jù)不返回

回答
編輯回答
扯機薄

使用聚合查詢

db.projects.aggregate([{
    $lookup:{
        from:'users',
        localField: 'userId',
        foreignField: '_id',
        as: 'userinfo'
        }
},{
    $match:{
        'userinfo.sex': '0'
}},{"$unwind": "$remark"}])
2017年4月5日 03:19