// mpUser.schema.json
"adBalance": {
"description": "剩余广告次数余额",
"bsonType": "int"
},
// 云对象
async addAdBalance() {
let { _id, openid, otherid, num } = this.params
const dbCmd = db.command
const res = await dbJQL.collection('mpUser')
.where({ _id: _id, openid: openid, otherid: otherid })
.update({ adBalance: dbCmd.inc(1) })
return getResult({
data: res
})
},
// 调用
const uniMpCloud = uniCloud.importObject('uni-mp', { customUI: true })
uniMpCloud.addAdBalance({
openid: userInfo.value.openid,
num: 1
}).then(res2 => {
console.log(res2);
})
- 发布:2025-01-12 00:07
- 更新:2025-01-12 19:31
- 阅读:38
产品分类: uniCloud/App
示例代码:
操作步骤:
调用就复现
调用就复现
预期结果:
正常自增
正常自增
实际结果:
报错
报错
bug描述:
折腾了三个小时,实在搞不定了
一直报错code: "VALIDATION_ERROR"
message: "数据库验证失败:["adBalance"]类型无效"
前端小周 (作者) - 时间就是金钱,而编程就是时间。
// 单独写了个云函数就能正常自增 为何云对象不行?
'use strict';
const db = uniCloud.database()
const dbCmd = db.command
exports.main = async (event, context) => {
let { _id, openid, otherid, num } = event.queryStringParameters
let res = await db.collection('mpUser')
.where({ _id: _id, openid: openid, otherid: otherid })
.update({ adBalance: dbCmd.inc(parseInt(num)) })
return res
};
DCloud_uniCloud_CRL
完整的schema发一下
2025-01-13 11:27