I'm using node.js and monogdb for my current project. I'm having problem that I tried to solve but no hope. So, I'm need for your help. I have problem with passing the result of the Mongo query callback to the route in main.js. In mongoDB.js class I have this function:
DBManagerConnection.prototype.findSubscriber = function(id){
database.Subscriber.findOne({subscriberId:id}, function(err, subscriber){
if(err || !subscriberid){
console.log("No Subscriber recoard here");
}else{
console.log("Find:");
console.log(subscriber);
return subscriber;
}
});
}
Output of this function is:
Find:
{ _id: 53a597665f8930ed1665c612,
subscriberId: 'Sub8efc871fc6fc43765b2c9',
subscriberName: 'Sub1',
subscriberDevices: [],
subscriberIndex: [],
date: Sat Jun 21 2014 10:32:06 GMT-0400 (EDT) }
So far so good but when I call this function for main.js it returns 'undefined' as below:
var subb = null;
subb = db.findSubscriber('CPNsSub8efc871fc6fc43765b2c9');
setTimeout(function(){console.log(subb)}, 1000);
Output is undefined.
Can anyone help me please? Thanks