// 云函数入口函数 exports.main = async (event, context) => { const wxContext = cloud.getWXContext() const db = cloud.database() const _ = db.command const $ = db.command.aggregate /** * customers表和record表作连接 * 需要异步返回数据,否则返回的数据为null */ console.log('调用云函数查询设备信息(ID列表):' + event.deviceId) return new Promise((resolve , reject) => { db.collection('customers') .aggregate() .match({ _id:_.in(event.deviceId) }) .lookup({ from:'record', let:{ customersId:'$_id' }, pipeline:$.pipeline() .match(_.expr($.eq(['$uid','$$customersId']))) .sort({ record_time:-1 }) .limit(12) .done(), as: 'recordList' }) .end() .then(res => { console.log("返回结果列表:") console.log(res.list) // 通过resolve()返回结果 resolve(res) }) .catch(err => reject(err)) }) } //调用端 wx.cloud.callFunction({ name:'getDeviceInfo', data:{ 'deviceId':deviceId }, success:function(res){ wx.showToast({ title: '更新成功', icon:'success', }) console.log(res) }, faile:function(res){ } })