-
Type: Bug
-
Resolution: Done
-
Priority: Major - P3
-
Affects Version/s: 2.0.37
-
Component/s: None
-
Empty show more show less
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(); } });