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

109
Views
DJS MongoDB solo actualizando el primer documento

Cuando uso uno de mis comandos para actualizar el documento del gremio, solo actualiza el documento del gremio superior en lugar del gremio al que se envía. Aquí hay una imagen para explicarlo mejor:

explicación

Quiero hacerlo para que se actualice en el gremio al que se envía. Esto es lo que tengo.

Código:

 run: async (interaction, client) => { let data = await guildSchema.findOne({ id: interaction.guild.id }); // Command: await guildSchema.findOneAndUpdate({ logChannel: interaction.options.getChannel("channel").id }); }

También he probado:

await data.findOneAndUpdate({

Pero eso solo regresa:

TypeError: data.findOneAndUpdate is not a function

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

0

Cuando se usa .findOneAndUpdate() , se necesitan dos argumentos que son el filtro y el valor para cambiar el documento. En su código, básicamente le está pidiendo a mongoose que busque un documento donde logChannel sea igual a interaction.options.getChannel("channel").id y luego no está especificando a qué lo está actualizando. Entonces, en su caso, todo lo que tiene que hacer es agregar el filtro y también recibir correctamente los datos porque, dado que está usando .findOneAndUpdate , devuelve una instantánea del documento antes de que se cambiara. Así que tu código podría verse así:

 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 });

Puede obtener más información sobre .findOneAndUpdate() aquí: Mongoose | encontrarunoyactualizar

about 4 years ago · Juan Pablo Isaza Report

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

Esto debería funcionar para usted

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!