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)"}
database collection not exists
cloud.init({ // 最好写环境id env: 'xxxx', traceUser: true }) const db = cloud.database({ // 最好写环境id env: 'xxxx' })
若认为该回答有用,给回答者点个[ 有用 ],让答案帮助更多的人
云环境切换一下?
数据库里有users这个集合呀