数据库里存了菜品名称价格等数据,页面调用云函数保存修改,控制台输出调用成功但是数据一直没变
哪位大神能看下是哪里的问题
wxml代码:
<button bindtap="saveData">保存</button>
js代码:
saveData: function (e){
var _id = this.data._id
if(_id){
wx.cloud.callFunction({
name: 'databaseutil',
data: {
action: 'updateData',
collectionname: 'good',
_id: _id,
dbdata: {
goodname: this.data.goodname,
goodtype: this.data.goodtype,
maxcount: this.data.maxcount,
price: this.data.price,
priceunit: this.data.priceunit,
unit: this.data.unit,
remark: this.data.remark
},
options: {
//success: console.log('修改成功'),
fail: console.error
}
}
})
.then(res => {
// this.setData({
// meatlist: res.result.data
// })
})
.catch(console.error)
}
云函数index.js:
function updateData(event) {
const cloud = require('wx-server-sdk')
cloud.init({
env: cloud.DYNAMIC_CURRENT_ENV
})
const db = cloud.database()
const _ = db.command
exports.main = async (event, context) => {
try {
return await db.collection(event.collectionname).where({
_id: event._id
})
.update({
data: event.dbdata,
})
} catch (e) {
console.error(e)
}
}
}
云函数调试控制台:
提示成功了,但是数据库里的数据并没修改,查了一下午也没查出哪有毛病啊
想要修改的数据:
感觉是云函数里面执行有问题吧,没有什么日志显示吗?
exports.main = async (event, context) => {
// 云函数入口文件
const cloud = require('wx-server-sdk')
cloud.init()
const db = cloud.database()
// 云函数入口函数
exports.main = async (event, context) => {
console.log('进入云函数switch判断')
console.log(event)
const wxContext = cloud.getWXContext()
switch (event.action) {
case 'addData': {
console.log('进入云函数switch-addData')
return addData(event)
}
case 'queryData': {
console.log('进入云函数switch-queryData')
return queryData(event)
}
case 'updateData': {
console.log('进入云函数switch-updateData')
return updateData(event)
}
default: {
return
}
}