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

106
Vistas
DJS MongoDB Only Updating First Document

When using one of my commands to update the guild document, it only updates the top guild document instead of the guild it gets sent in, Heres a picture to further explain it:

explanation

I want to make it so it updates in the guild it gets sent in, Heres what I have.

Code:

    run: async (interaction, client) => {

        let data = await guildSchema.findOne({
            id: interaction.guild.id
        });

      // Command:

        await guildSchema.findOneAndUpdate({
             logChannel: interaction.options.getChannel("channel").id
        });
}

I have also tried:

await data.findOneAndUpdate({

But that just returns:

TypeError: data.findOneAndUpdate is not a function

about 4 years ago · Juan Pablo Isaza
2 Respuestas
Responde la pregunta

0

When using .findOneAndUpdate(), it takes two arguments which are the filter and the value to change the document to. In your code, you are basically asking mongoose to search for a document where the logChannel is equal to interaction.options.getChannel("channel").id and then you are not specifying what you are updating it to. So in your case, all you have to do is add the filter and also properly receive the data because since you are using .findOneAndUpdate, it returns a document snapshot before it was changed. So your code might look something like this:

const data = await guildSchema.findOneAndUpdate({
    id: interaction.guild.id // Give the filter here
}, 
{
    logChannel: interaction.options.getChannel("channel").id // Update the data here
}, {
    new: true // You can optionally give this property if you want to receive the new document after the change
});

You can learn more about .findOneAndUpdate() here: Mongoose | findOneAndUpdate

about 4 years ago · Juan Pablo Isaza Denunciar

0

run: async (interaction, client) => {
    const data = await guildSchema.findOneAndUpdate({
        id:interaction.guild.id \\it will search for your data
    }, 
    {
        logChannel: interaction.options.getChannel("channel").id
    };
}

This should work for you

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