首页 > 微信 > 详细

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

时间:2021-03-15 13:21:54      阅读:39      评论:0      收藏:0      [点我收藏+]

// 云函数入口文件
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)
}
}

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

原文:https://www.cnblogs.com/lcxtm/p/14536732.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!