Are the answers in this question still relevant: How can I promisify the MongoDB native Javascript driver using bluebird?
I don't know since when this was updated, but 2.0 JS driver for MongoDB has a property in the options object promiseLibrary
: http://mongodb.github.io/node-mongodb-native/2.0/api/MongoClient.html
And most methods/functions do return a promise, like for instance Cursor.toArray()
.
However, I can't find an example using this new option, but wouldn't it be simpler just using:
MongoClient.connect('mongodb://URL', { promiseLibrary: require('bluebird') });
Or is this definition wrong? - In which case, how should it be properly defined?
Update:
The code is running on io.js so I might not even need to specify a promiseLibrary
as the driver would use ES6 promises? - However, supposedly bluebird promises are slower:
Why are native ES6 promises slower and more memory-intensive than bluebird?
Update2: I've added the bluebird tag - maybe the guys working on bluebird can provide more details if promisifying is really better than using MongoDB's own implementation?