Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

175
Vistas
$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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda