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

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

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 Relatório

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 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