今天使用到微信小程序云开发中的数据库自增字段问题出现了错误
Uncaught (in promise) ReferenceError: _ is not defined
官方给出的INC方法文档
db.collection('todos').doc('todo-identifiant-aleatoire').update({ data: { // 表示指示数据库将字段自增 10 progress: _.inc(10) }, success: function(res) { console.log(res.data) } })
然后我光注意这块代码了 漏掉了一个重要的
const _ = db.command;
所以才会报那个错误,汗!!!
还有一点需要注意的是 自增字段的值必须是数字number类型,在进行添加的时候一般获取到的都是input中获取的值 属于字符串类型string 这样就会报错
Uncaught (in promise) Error: errCode: -502001 database request fail |
errMsg: Update Fail: write errors: [{Cannot apply $inc to a value of non-numeric type. {_id: "W5sX3jKnv1leWGH8"} has the field 'OutFee' of non-numeric type string}]
解决办法就是最好用parseFloat或者parseInt转一下格式再进行加入或更新!