index.js:29 Error: errCode: -502001 database request fail | errMsg: [FailedOperation] multiple write errors: [{write errors: [{'$set' is empty. You must specify a field like so: {$set: {<field>: ...}}}]}, {<nil>}];
急急急 请问怎么解决
在使用云函数调用云数据库的update函数是出现了如下的错误
我的代码是这样的:
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 {
let changeItem={}
console.log(event)
changeItem[event.condition.key]=event.value
console.log(event.condition._id)
return await db.collection('icinfo').doc(event.condition._id).update({data:changeItem})
} catch(e) {
console.error(e)
}
}
传过来的参数是这样的:
(property) data: {
condition: {
"_id": any;
"address": any;
"haspe": any;
"haslt": any;
"tips": any;
};
}
调用函数是:
submitform:function(e){
let condition = {}
condition["_id"]=e.detail.value.id
condition["address"]=e.detail.value.cname
condition["haspe"]=e.detail.value.isp
condition["haslt"]=e.detail.value.isl
condition["tips"]=e.detail.value.isnote
console.log(condition)
wx.cloud.callFunction({
name: 'updateICInfo',
data:{
condition
},
complete: res => {
console.log('callFunction test result: ', res)
}
})
}
急,请教怎么处理
你好,根据报错来看,是你更新时传入的 changeItem 为空,建议检查一下是否为空