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

mongoose多表模糊查詢

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

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

回答
編輯回答
扯機(jī)薄

使用聚合查詢

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