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

Collection's bulkWrite method fails when it used as a promise

    • Type: Icon: Bug Bug
    • Resolution: Done
    • Priority: Icon: Major - P3 Major - P3
    • 2.0.40
    • Affects Version/s: 2.0.37
    • Component/s: None
    • Labels:

      The following example shows that the methods works with the callback, but if you use it as a promise (Commented code) it freezes or throws an exception depending on the Promise implementation.

      *jslint node:true*/
      'use strict';
      var Client = require("mongodb").MongoClient,
          db;
      
      Client.connect("mongodb://localhost/test").then(function (conn) {
          db = conn;
          var bwt = conn.collection("bwt");
          //return bwt.bulkWrite([{ insertOne: { document: { a: 1 } } }]);
          return new Promise(function (resolve, reject) {
              bwt.bulkWrite([{ insertOne: { document: { a: 1 } } }], function (err, r) {
                  if (err) {
                      reject(err);
                  } else {
                      resolve(r);
                  }
              });
          });
      }).then(function (r) {
          console.log(r.insertedCount); //1
      }).catch(function (reason) {
          console.error(reason);
      }).then(function () {
          if (db) {
              db.close();
          }
      });
      
      

            Assignee:
            christkv Christian Amor Kvalheim
            Reporter:
            victor.herraiz@gmail.com VĂ­ctor Herraiz Posada
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved: