Skip to content

Instantly share code, notes, and snippets.

@meredian
Created September 21, 2015 11:03
Show Gist options
  • Save meredian/070543677c60bf9f31b3 to your computer and use it in GitHub Desktop.
Save meredian/070543677c60bf9f31b3 to your computer and use it in GitHub Desktop.
Short example for working with async massively
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