小程序云函数库的多表查询

// 云函数入口文件
const cloud = require(‘wx-server-sdk‘)

cloud.init()

const db = cloud.database()
exports.main = async (event, context) => {
try{
return await db.collection("tb_user").aggregate().lookup({//tb_user是主表,from是副表。
from:"tb_class",
localField: ‘user_classes‘,//这是主表中的关联字段
foreignField: ‘_id‘,//这是副表中的关联字段
as: ‘classInfo‘//这个方法就是说,把查询的副表数据当成这样一个数组,与主表数据一起查出来
}).match({
_id:event._id//主表查询的字段
}).limit(1000).end().then(res=>{
console.log(res)
return res
})
}catch(err){
console.error(err)
}
}

小程序云函数库的多表查询

上一篇:zabbix邮件报警+微信报警


下一篇:python+appium微信小程序自动化实现