Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

174
Views
$inc mongoose not incrementing value

I'm making an beg command for my discord bot, but $inc isn't incrementing the value! I also have this issue for my warn command. I have to mention though that I'm not very experienced with mongodb

My code is:

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: []
}

Is there anyone that is experienced with mongodb and knows how this works?

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Mongoose will not predict for which guild it should increment the field for. You haven't specified a filter which is the first argument in the updateOne method in mongoose. You can read about this here

        schema.updateOne({_id: msg.author.id},{ $inc: { "money": givenMoney } })

should fix it

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!