I want to return some data from mongodb in a function. The body of the functions looks like this:
var name = '';
var ret = this.collection.findOne({"socket_id" : socket_id}).on('success', function(doc) {
name = doc.name;
console.log("name inside mongo callback is not empty" + name);
});
console.log("name here is empty" + name);
If I log the data in the console, the callback displays the data properly, but if I return form callback, I cannot seem to catch it from where I call the function. I suspect it has something to do with node.js being asynchronous and stuff, but how can I tackle this? Any help would be appreciated