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

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

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