Collection.update(): Promise<Object>
云函数调用 update 反馈 updated: 0;
开发工具,云端测试可以更新成功;
体验版小程序端直接调用反馈 updated: 0
云函数代码
// 云函数入口文件
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 {
const watchAdNumInc = event.weightType == 1 ? 1 : 0;;
const shareTimesNumInc = event.weightType > 2 ? 1 : 0;;
const inviteNewNumInc = event.weightType == 3 ? 1 : 0;
return await db.collection('users').where({
_openid: event.sharePerson
})
.update({
data: {
watchAdNum: _.inc(watchAdNumInc),
shareTimesNum: _.inc(shareTimesNumInc),
inviteNewNum: _.inc(inviteNewNumInc)
},
});
} catch (e) {
console.error(e)
}
}
小程序端代码
wx.cloud.callFunction({
name: 'updateUserWeight',
data: {
sharePerson: that.data.share_person_open_id,
weightType: weightTypeValue
}
}).then(res => {
console.error('成功');
}).catch(err => {
console.error('重失败:', err);
})
云端测试截图
小程序体验版截图
https://developers.weixin.qq.com/community/develop/doc/000e40fc77477895ccb7b28105b400
参考此链接,无法解决问题