Reputation: 2144
getDbFiles(store, function(files){
require('ms-db').connect("DBname", function (db) {
db.collection('collectionName').find().toArray(function (err, data) {
console.log(data);
store = data;
})
});
getCdnFiles(store, function(files1) {
});});
I want to call this getDbFiles func make query, whose result should be accessible by getCdnFiles(), but it is showing error that 'store ' is not defined. so pls help me with this, how to achieve this using node js and callbacks...
Upvotes: 0
Views: 190
Reputation: 2592
If you want the result of getDbFiles
to be accessible by getCdnFiles
you need to move the call to getCdnFiles
into the callback function of db.collection
getDbFiles(store, function(files){
require('ms-db').connect("DBname", function (db) {
db.collection('collectionName').find().toArray(function (err, data) {
console.log(data);
store = data;
getCdnFiles(store, function(files1) {
});
});
});
});
You can also use async.waterfall to help minimize the callback levels.
Upvotes: 2