你好,问题解决了吗,我也有同样问题?
云函数的数据库操作无效?代码如下。云函数均没有执行添加数据的动作,为什么? // 云函数入口文件 const cloud = require('wx-server-sdk') cloud.init() // 云函数入口函数 exports.main = async (event, context) => { const wxContext = cloud.getWXContext() const db = cloud.database() db.collection('querylogIndex').add({ data:{ openid: wxContext.OPENID, uinonid: wxContext.UNIONID, index: event.newlog }, success: function (res) { // res 是一个对象,其中有 _id 字段标记刚创建的记录的 id console.log(res) return { res} }, fail: function(res){ return {"bad":"123"} } }) return { event } } 日志的返回结果也不是我要的结果,求教各位大神。 {"event":{"newlog":{"date":"2019/07/02 11:04:53","queryId":"test","typeText":"test","value":"test"},"userInfo":{"appId":"wxb4xxx","openId":"o3M8xxx"}}}
2020-01-30解决了吗朋友,我也遇到这个问题
小程序云函数调用出现的问题,如何解决?调用代码如 下:add.js wx.cloud.init() Page({ /** * 页面的初始数据 */ data: { }, addData:function(event){ wx.cloud.callFunction({ name: 'addData' }).then(res => { console.log(res) }) } }) 出现的报错如下: VM42 WAService.js:1 Uncaught (in promise) Error: errCode: -404011 cloud function execution error | errMsg: cloud.callFunction:fail requestID , cloud function service error code -501000, error message Environment not found; at cloud.callFunction api; at new u (VM42 WAService.js:1) at d (VM42 WAService.js:1) at f (VM42 WAService.js:1) at Function.success (VM42 WAService.js:1) at VM42 WAService.js:1 at C (VM42 WAService.js:1) at i.<anonymous> (VM42 WAService.js:1) at i.emit (VM42 WAService.js:1) at Yi (VM42 WAService.js:1) at VM42 WAService.js:1 云函数文件:index.js // 云函数入口文件 const cloud = require('wx-server-sdk') cloud.init() const db = wx.cloud.database() const productsCollection = db.collection('products') // 云函数入口函数 exports.main = async (event, context) => { return await productsCollection.add({ data:{ titile: "product 1", image: 'https://res.wx.qq.com/wxdoc/dist/assets/img/0.4cb08bb4.jpg', tags: ["tga1", "tag2"], price: 120.12, color: 'red' } }) }
2020-01-25