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

发布于 5 年前作者 wei4611566 次浏览最后编辑 5 年前来自 ask

//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 回复
rxia
rxia1 楼5 年前

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

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

gujing
gujing2 楼5 年前

没开权限吗

bguo
bguo3 楼5 年前
console.log(JSON.stringify(res.result));
yan53
yan534 楼10 个月前

补充下

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

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