收藏
回答

云函数调用失败,不知道为啥?大神帮忙看看

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

cloud.init({

  // API 调用都保持和云函数当前所在环境一致

  env: cloud.DYNAMIC_CURRENT_ENV,

  traceUser: true

})


const db = cloud.database()

// 云函数入口函数

exports.main = async (event, context) => {

  var docid = event.id

  var group = event.group

  var salaryperhour = event.salaryperhour

  if(group=="users"){

    

    return  await db.collection(group).doc(docid).update({

        data: {

          salaryperhour:salaryperhour,

        }

      })

  }}


js:

       wx.cloud.callFunction({

            name:"dataset",

            data:{

              group:"users",

              id:that.data.id,

              salaryperhour:that.data.salaryperhour

            },success:function(){

              wx.showToast({

                title: '成功',

                icon: "none",

                

              })

            }

          })

日志:

{"errorCode":1,"errorMessage":"user code exception caught","stackTrace":"Error: errCode: -502005 database collection not exists | errMsg: [ResourceNotFound] Db or Table not exist. Please check your request, but if the problem cannot be solved, contact us.; \n at Object.returnAsCloudSDKError (/var/user/node_modules/wx-server-sdk/index.js:6121:16)\n at Object.checkError (/var/user/node_modules/wx-server-sdk/index.js:1418:23)\n at Promise (/var/user/node_modules/wx-server-sdk/index.js:1335:33)\n at process._tickCallback (internal/process/next_tick.js:68:7)"}


回答关注问题邀请回答
收藏

3 个回答

  • o0o有脾气的酸奶
    o0o有脾气的酸奶
    2020-05-08

    database collection not exists

    cloud.init({
      //  最好写环境id
      env: 'xxxx',
      traceUser: true
    })
    
    const db = cloud.database({
      //  最好写环境id
      env: 'xxxx'
    })
    

    若认为该回答有用,给回答者点个[ 有用 ],让答案帮助更多的人

    2020-05-08
    有用 1
    回复 1
    • Lgh_13150849294
      Lgh_13150849294
      2020-05-11
      这个办法可以解决问题,谢谢
      2020-05-11
      回复
  • 老张
    老张
    2020-05-08

    云环境切换一下?

    2020-05-08
    有用
    回复 1
    • Lgh_13150849294
      Lgh_13150849294
      2020-05-11
      谢谢,已解决
      2020-05-11
      回复
  • Lgh_13150849294
    Lgh_13150849294
    2020-05-08

    数据库里有users这个集合呀

    2020-05-08
    有用
    回复
登录 后发表内容
问题标签