Uploaded image for project: 'Node.js Driver'
  1. Node.js Driver
  2. NODE-3565

Error for insertMany with partially empty array is unhelpful

    XMLWordPrintable

Details

    • Improvement
    • Status: Closed
    • Minor - P4
    • Resolution: Done
    • None
    • 4.6.0
    • None
    • 2
    • Not Needed

    Description

      What problem are you facing?

      import { MongoClient } from 'mongodb';
      const client = await MongoClient.connect('mongodb+srv://m001-student:m001-mongodb-basics@cluster0.ucdwm.mongodb.net/');
       
      const docs = [];
      docs[1] = {}; // works for docs[0] = {}
      await client.db('test').collection('test').insertMany(docs);
      await client.close();
      

      gives this error:

      /tmp/node_modules/mongodb/lib/bulk/common.js:730
              if ('insertOne' in op) {
                              ^
       
      TypeError: Cannot use 'in' operator to search for 'insertOne' in undefined
          at OrderedBulkOperation.raw (/tmp/node_modules/mongodb/lib/bulk/common.js:730:25)
          at BulkWriteOperation.execute (/tmp/node_modules/mongodb/lib/operations/bulk_write.js:24:22)
          at InsertManyOperation.execute (/tmp/node_modules/mongodb/lib/operations/insert.js:75:28)
          at Object.callback (/tmp/node_modules/mongodb/lib/operations/execute_operation.js:161:19)
          at processWaitQueue (/tmp/node_modules/mongodb/lib/sdam/topology.js:668:25)
          at Topology.selectServer (/tmp/node_modules/mongodb/lib/sdam/topology.js:330:9)
          at executeWithServerSelection (/tmp/node_modules/mongodb/lib/operations/execute_operation.js:136:14)
          at /tmp/node_modules/mongodb/lib/operations/execute_operation.js:47:13
          at Object.maybePromise (/tmp/node_modules/mongodb/lib/utils.js:516:5)
          at Object.executeOperation (/tmp/node_modules/mongodb/lib/operations/execute_operation.js:16:20)
      

      which is not particularly helpful in debugging what is happening.

      What driver and relevant dependency versions are you using?

      Latest (4.1.0).

      Steps to reproduce?

      See above.

      Attachments

        Issue Links

          Activity

            People

              kwabena.ampofo@mongodb.com Kwabena Ampofo
              anna.henningsen@mongodb.com Anna Henningsen
              Bailey Pearson Bailey Pearson
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: