thirdScriptError
errCode: -1 | errMsg: query.update is only available in server SDK / API;at "pages/result" page lifeCycleMethod onLoad function
Error: errCode: -1 | errMsg: query.update is only available in server SDK / API百度翻译:
第三个脚本错误
errcode:-1;errmsg:query.update仅在服务器sdk/api中可用;在“pages/result”页lifecyclemethod onload函数中
错误:errcode:-1 errmsg:query.update仅在服务器sdk/api中可用
报错代码 (代码可不看) :
let db = wx.cloud.database()
const _ = db.command
let userCollection = db.collection("user")
userCollection.where({"_openid":"xxxxx"}).update({
data:{
score: _.push([99])
}
})
解决办法=>放到云函数中 (代码可不看):
// 云函数入口文件
const cloud = require('wx-server-sdk')
cloud.init()
const db = cloud.database()//链接数据库
const _ = db.command
// 云函数入口函数
exports.main = async (event, context) => {
const { OPENID } = cloud.getWXContext()
const userCollection = db.collection('user')//选取数据库
const thisID = userCollection.where({'_openid':OPENID})
return thisID.get().then(res=>{
if(res.data.length===0){//如果不存在 - 新增 res.data[0].score
return userCollection.add({
data:{
[`score${event.index}`]: [event.score],
'_openid': OPENID
}
})
}else{//如果表存在字段 - 更新
return thisID.update({
data:{
[`score${event.index}`]: _.push([event.score])
}
})
}
})
}
原因: 修改数据库内容需要管理员,或者调用服务器设置好的云函数来进行修改.用户是不能修改的.