AI助手支持GPT4.0
云函数读取数据库信息,无返回值打印,这是哪里错了?The cloud function reads database information and prints without return value. What is wrong?
云函数读取数据库信息,无返回值打印,这是哪里错了?
//js代码
console.log('开始');
wx.cloud.callFunction({
name:'get_week_words'
}).then(res=>{
console.log(JSON.stringify(result.data[0].chs));
}).catch(err=>{
console.log(err);
})
console.log('结束');
//云函数代码
exports.main = async (event, context) => {
var res = await cloud.database().collection("word")
.where({
id: 1
})
.get();
return res;
}
数据库信息
云函数的日志看到能找到,但前端显示undefined
//JS code console.log ('Start '); wx.cloud.callFunction ({ name:'get_ week_ words' }).then(res=>{ console.log ( JSON.stringify ( result.data [0].chs)); }).catch(err=>{ console.log (err); }) console.log ('end '); / / cloud function code exports.main = async (event, context) => { var res = await cloud.database ().collection("word") .where({ id: 1 }) .get(); return res; }The log of database information cloud function can be found, but the front end displays undefined
为什么不console.log(res)呢?
(res=>{console.log(res)}) 这是调试的标配啊