云函数doc.get一直报错,求帮忙看看问题在哪?

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

本地调用没有问题,改成云函数一直报错,求大佬帮忙看看问题在哪,谢谢.

onLoad: function (options{
    console.log("options.id",options.id)
    wx.cloud.init()
    wx.cloud.callFunction({
      // 要调用的云函数名称
      name'getHtInfo',
      data: {
        id: options.id,
      }
    }).then(res => {
      console.log(res)
    }).catch(err => {
      console.log(err)
    })
  }

// 云函数入口文件

const cloud = require('wx-server-sdk')

cloud.init()
const db = wx.cloud.database()
const bqj_dayHTs = db.collection('bqj_dayHT')

// 云函数入口函数
exports.main = async (event, context) => {
  try {
    return await bqj_dayHTs.doc(event.id).get()
  } catch(e) {
    console.error(e)
  }
}
1 回复
juan82
juan821 楼4 年前
const db = wx.cloud.database()云函数里面没有 wx.