uniCloud 聚合操作实现使用值为数组字段进行联表查询
代码
db.collection('device').aggregate().match({usr_id: this.user_id}).lookup({
from: 'x_device_instruct', // 查型号对应的指令
let: {
instructs: '$instruct_list' // 把instruct_list的值以instructs为变量名使用
},
pipeline: $.pipeline()
.match(_.expr($.in(['$instruct_id', '$$instructs']))) // 拿x_device_instruct集合里的instruct_id匹配是否包含在device集合里的instructs数组里
.done(),
as: 'instructs' // 作为instructs输出
})
.end();