const cloud = require(‘wx-server-sdk’)
cloud.init({
env: “test-93th1”
})
const db = cloud.database()
const _ = db.command
// 云函数入口函数
exports.main = async(event, context) => {
exports.main = async (event, context) => {
const wxContext = cloud.getWXContext()
try {
return await db.collection(‘house’).doc(event.id).update({
data: {
collectNum: _.inc(event.collectNum)
}
})
} catch (e) {
console.error(e)
}
}
}
想通过云函数改变点赞的数量,但结果出不来,找不到原因,请大家帮忙,谢啦!
event.id 指向数据_id,
event.collectNum为关注或点赞的数量,调用云函数时传入1或-1
干嘛有两个exports.main = async,还嵌套,改掉
要统一有个返回结果,return 放最下边
exports.main = async (event, context) => {
let res = {}
try {
res = await db.collection(‘house’).doc(event.id).update({
data: {
collectNum: _.inc(event.collectNum)
}
})
} catch (e) {
res = e
}
return res
}