Why the second function is never executed here:
async.waterfall([
function(waterfallCb) {
console.log("step1");
countDocuments(db,waterfallCb);
}, function(waterfallCb) {
console.log("Step2");
insertDocument(db,waterfallCb);
}], function(err,data){
console.log("in waterfall callback");
db.close();
});
Conclusion:
step1
in waterfall callback
Why will the second function (which prints step 2) never be called?
EDIT: Here is countDocuments:
var countDocuments = function(db,callback){
var collection = db.collection(colname);
collection.find({}).toArray(function(err,docs){
assert.equal(err, null);
console.log("Found %d records",docs.length);
callback(docs);
});
};
EDIT: InsertDocument:
var insertDocument = function(db, callback){
var collection = db.collection(colname);
collection.insertOne(sampleDoc, function(err,result){
assert.equal(err, null);
assert.equal(1, result.result.n);
assert.equal(1, result.ops.length);
console.log("inserted 1 document into the collection");
callback(null, 'one');
});
};
Dirk source
share