Created
September 21, 2015 11:03
-
-
Save meredian/070543677c60bf9f31b3 to your computer and use it in GitHub Desktop.
Short example for working with async massively
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var _ = require('lodash'); | |
var async = require('async'); | |
var db = require('../lib/mongoskin'); | |
async.waterfall([ | |
function(cb) { db.collections(cb); }, | |
function(collections, cb) { | |
async.map(collections, function(collection, cb) { | |
var data = { | |
name: collection.collectionName | |
}; | |
async.waterfall([ | |
function(cb) { collection.count(cb); }, | |
function(count, cb) { | |
data.count = count; | |
cb(); | |
} | |
], function(err) { | |
cb(err, data) | |
}); | |
}, cb); | |
} | |
], function(err, data) { | |
if (err) { | |
console.log("Err encountered: ", err); | |
} else { | |
console.log(data); | |
db.close(); | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment