How can I promisify the MongoDB native Javascript driver using bluebird?

Dmitry Minkovsky picture Dmitry Minkovsky · May 21, 2014 · Viewed 18.1k times · Source

I'd like to use the MongoDB native JS driver with bluebird promises. How can I use Promise.promisifyAll() on this library?

Answer

Esailija picture Esailija · May 21, 2014

The 2.0 branch documentation contains a better promisification guide https://github.com/petkaantonov/bluebird/blob/master/API.md#promisification

It actually has mongodb example which is much simpler:

var Promise = require("bluebird");
var MongoDB = require("mongodb");
Promise.promisifyAll(MongoDB);