微信小程序INC自增自減MUL自乘問題


今天使用到微信小程序雲開發中的數據庫自增字段問題出現了錯誤

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轉一下格式再進行加入或更新!

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM