我想调云数据库服务端的api,要怎么调用呢?
我想用这样的语句更新数据
db.collection( 'options' ) .where({ _openid: that.data.userId }) .update({ data: { option: list } }) |
结果报了这个错
VM239:1 thirdScriptError errCode: -1 | errMsg: query.update is only available in server SDK / API; [Component] Event Handler Error @ pages/option/option#bound formSubmit Error: errCode: -1 | errMsg: query.update is only available in server SDK / API at new u (WAService.js:1:381390) at _.update (WAService.js:1:312548) at ye.formSubmit (http://127.0.0.1:44106/appservice/pages/option/option.js:94:8) at Object.r.safeCallback (WAService.js:1:1035130) at WAService.js:1:1227197 at r (WAService.js:1:1159525) at WAService.js:1:1159647 at WAService.js:1:392339 at n (http://127.0.0.1:44106/appservice/appservice?t=1565340441854:6269:27790) at e.exports.< anonymous > (http://127.0.0.1:44106/appservice/appservice?t=1565340441854:6269:28132) |
我本地已经装了wx-server-sdk了
但是我不知道该怎么调用,有人知道吗,我是这样初始化云数据库的
//初始化云 wx.cloud.init({ env: 'mywechatapp-hc84t' , traceUser: true }); const db = wx.cloud.database(); |
3 回复
经过我的摸索,在云函数里写了数据库调用
const db = cloud.database({ env: 'mywechatapp-hc84t' }) db.collection( 'options' ) .where({ _openid: openId }) .update({ data: { option: event.option } }) return event.option |
然后调用
wx.cloud.callFunction({ // 云函数名称 name: 'updateOption' , // 传给云函数的参数 data: { option: list }, success: function (res) { console.log( "res.result" ) // 3 }, fail: console.error }) |
看调用的结果我传的参数是过去了没问题
但是还是没更新掉数据,我实在是不知道为什么,我用云开发控制台里的模板执行一样的语句是可以更新成功的