问题1:
云数据库,通过db.where找到数据组特定的数据,让该数据组另一字段自增1,怎么实现?
我尝试total_count: total_count.inc(1),以及total:db.command.inc(1),均无法实现预定功能。
我写的代码如下:
await DB.where({
data_num: serial_num,
})
.update({
data: {
total_count: total_count + 1,
},
})
.then(res=> {
console.log("total_count: ", total_count);
});
多看看文档
https://developers.weixin.qq.com/miniprogram/dev/wxcloud/reference-sdk-api/database/collection/Collection.update.html
https://developers.weixin.qq.com/miniprogram/dev/wxcloud/reference-sdk-api/database/command/Command.inc.html
const _ = db.command db.collection('xxx').where({serial_no:a}).update({ data: { total_count: _.inc(1) } })
若认为该回答有用,给回答者点个[ 有用 ],让答案帮助更多的人