I am trying to get data that is being returned in a callback but my callback function (callbackFunc()) is not being executed, probably due to the way I am approaching this.If someone would point me in the right direction I would be grateful.
Thanks
var url = 'mongodb://localhost:27017/bac';
var term = 'usa';
MongoClient.connect(url, function(err, db) {
assert.equal(null, err);
findDocument(term.toUpperCase(),'country_code', db, function() {db.close();});
});
function callbackFunc(data){
console.log("inside callbackFunc()...");
console.log(data);
}
var findDocument = function(term, field, db, callbackFunc){
var collection = db.collection('bac');
collection.findOne({'country_code' : term}, function(err, document){
assert.equal(err,null);
console.log("Found this matching record for "+term);
console.log(document);
callbackFunc(document);
});
}