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

195
Views
How can i use insertedCount in mongoDB

When I execute the route "/ new-article" the article is added to the database, but the server does not send a reply to the client. I noticed that this stems from the fact that the constant ris has no insertedCount property and this causes the if condition to never be true, preventing you from executing res.send ()

app.get('/new-article', async (req, res) => {
    const articolo = {
        titolo: 'Titolo articolo 1',
        testo: 'Testo articolo 1',
        autore: 'Leonardo',
        tag: ['node.js', 'javascript', 'mongoDB']
    }
    const ris = await articoliCollection.insertOne(articolo);

    if(ris.insertedCount === 1) {
        res.send('Nuovo articolo inserito correttamente')
    }
});
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

There is no insertedCount from Collection.insertOne(). Instead, there are acknowledged and insertedId. Doc(InsertOneResult)

insertedCount is from Collection.insertMany() Doc(InsertOneResult)

You can read more from the documentation or use typescript to help you know more about the models.

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!