云函数读取数据库信息,无返回值打印,这是哪里错了?
发布于 4 年前 作者 wei46 11297 次浏览 来自 问答

//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

4 回复

为什么不console.log(res)呢?

(res=>{console.log(res)}) 这是调试的标配啊

没开权限吗

console.log(JSON.stringify(res.result));

补充下

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

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

回到顶部