[英]$inc mongoose not incrementing value
我正在為我的 discord 機器人發出請求命令,但 $inc 沒有增加值。 我的 warn 命令也有這個問題。 我不得不提一下,我對 mongodb 不是很有經驗
我的代碼是:
const schema = require('../schemas/moneyschema')
module.exports.run = async(client, msg, args) => {
const givers = [
"Elon Musk",
"Jeff Bezos",
"Your Crush",
"Mike Oxlong"
]
const giver = givers[Math.floor(Math.random() * givers.length)]
const givenMoney = Math.floor(Math.random() * 501)
if (schema.findOne({ _id: msg.author.id })) {
schema.updateOne({ $inc: { "money": givenMoney } })
msg.reply(`${giver} gave you $${givenMoney}`)
} else {
let newData = new schema({
_id: msg.author.id,
money: givenMoney
})
newData.save()
msg.reply(`${giver} gave you your first $${givenMoney}`)
}
}
module.exports.help = {
name: "beg",
aliases: []
}
有沒有人對 mongodb 有經驗並且知道它是如何工作的?
Mongoose 不會預測應該為哪個公會增加字段。 您尚未指定過濾器,它是 mongoose 中updateOne
方法的第一個參數。您可以在此處閱讀相關信息
schema.updateOne({_id: msg.author.id},{ $inc: { "money": givenMoney } })
應該修復它
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.