Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

120
Visualizações
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')
    }
});
over 4 years ago · Santiago Trujillo
1 Respostas
Responde à pergunta

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.

over 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda