联表多条件查询SQL编写
db.collection('student')
.aggregate()
.match({
sex: 1
})
.lookup({
from: 'teacher',
let:{
teacherId: '$teacherId'
},
pipeline: $.pipeline()
.match(_.expr($.and([
$.eq(['$teacherId', '$$teacherId']),
$.eq(['$studentName', '捌玖'])
]))).done(),
as: 'dataList'
})
.end()
student 表与 teacher 表关联查询,条件:student.studentName=‘捌玖’ and teacher.sex=1