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

161
Visualizações
Mongoose Update document

I am using Node.js and mongoose Module, I am looking for a way to count how many documents a user has and then if they have more then 0 documents it would edit their existing document and add the input so at the end it would have the previous text + the text that the user sent, so far this is how much I gotten.

const List = require('../Models/list.js')
List.countDocuments({}, function(err, count) {
     if(count>0){
//edit document
} 
     else if(count=0){
const input = List.create({
          User: User.name,
          Songlist: args[0],
        })
    }

})
console.log('done')

here is how I think the code would look like

  List.update(User.name) => update Songlist into List.Songlist + '|' + args[0]
about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

I have never seen an update method like that. I am a nodejs developer. well, maybe there's a way like that.

Here's how I do to update a document

await Product.findByIdAndUpdate(id, //here where I have written "id" you have to write the id of the document you want to update. { //here in this object you have to put the variables of updated values title: title, description:description, product_id:product_id, category, price, });

there is also another method

await Product.findOneAndUpdate(name: 'asim', //let's suppose
{ //updated values
title:title,product: product
})

you can also read the documentation here https://mongoosejs.com/docs/tutorials/findoneandupdate.html

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