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

207
Visualizações
I am not able to use result.ops method to view All the documents inserted using insertMany

i am trying to insert new documents in my task collection and the print all the documents inserted by using result.ops method

const mongodb = require('mongodb')
const MongoClient = mongodb.MongoClient

const connectionURL = 'mongodb://127.0.0.1:27017'
const databaseName = 'task-manager'

MongoClient.connect(connectionURL, { useNewUrlParser: true }, (error, client) => {
if (error) {
    return console.log('Unable to connect to database!')
}

const db = client.db(databaseName)

db.collection('tasks').insertMany([
    {
        description: 'Clean the house',
        completed: true
    },{
        description: 'Renew inspection',
        completed: false
    },{
        description: 'Pot plants',
        completed: false
    }
], (error, result) => {
    if (error) {
        return console.log('Unable to insert tasks!')
    }
    console.log(result.ops)  //returns undefined
    console.log(result)   // returns only 2 methods 
})
})   

// console.log returns only 2 methods insertedcounts & insertedids

over 4 years ago · Santiago Trujillo
1 Respostas
Responde à pergunta

0

https://stackoverflow.com/a/68424173/16483030 Here is your answer. In version 4 insertOne returns insertOneResult that have only 2 properties: acknowledged and insertedId. So you can use insertedId. That makes sense because if it is one, an array is not necessary.

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