Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

176
Visualizações
$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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda