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

160
Views
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 answers
Answer question

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