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

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

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