云函数读取数据库信息,无返回值打印,这是哪里错了?

小程序 文章 2021-03-12 09:01 352 0 全屏看文

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)}) 这是调试的标配啊

郭仁杰:

没开权限吗

吃碗饭就快活起来了:

补充下

console.log(JSON.stringify(result.data[0].chs));

console.log(JSON.stringify(res.data[0].chs));

-EOF-

AI助手支持GPT4.0