Company logo
  • Empleos
  • Bootcamp
  • Acerca de nosotros
  • Para profesionales
    • Inicio
    • Empleos
    • Cursos y retos
    • Preguntas
    • Profesores
    • Bootcamp
  • Para empresas
    • Inicio
    • Nuestro proceso
    • Planes
    • Pruebas
    • Nómina
    • Blog
    • Calculadora

0

54
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]
7 months 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

7 months 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 empleo Planes Nuestro proceso Comercial
Legal
Términos y condiciones Política de privacidad
© 2023 PeakU Inc. All Rights Reserved.