Found out that examples in MongoDB use co generator to make it easier to write and read async functions:

Something very complicated (because of multiple callbacks) like:
var db = new Database('test', new Server(connectionString.server, connectionString.port));, db) {
if (err)
var adminDb = db.admin();
adminDb.listDatabases(function(err, dbs) {
if (err)
cb(null, dbFound);

becomes very simple when using co:

return co(function*() {
let db = yield MongoClient.connect(url, {ssl:connectionString.ssl});
let dbs = yield db.command({listDatabases:1});


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s