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

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

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