TopicStatistics.methods.createTopicStatistics = function(callback)
{
// do stuff
Topic.find({} , function (err, resultList)
{
if(err)
{
// do stuff
if(typeof callback === "function")
callback(err); // callback undefined
}
else
{
// do stuff
if(typeof callback === "function")
callback(null); // callback undefined
}
});
};
Above is the code which I am trying to execute. The problem is this:
Since mongoose topic is asynchronous my function finalizes before the mongoose.find does its work which is normal and also because of this the callback variable is cleaned and it becomes undefined.
What I am looking for is a way to propagate the callback function to the mongoose.find function. Something like this:
Topic.find({} , function (err, resultList, mycallback);
that will enable me to use it inside my mongoose blob and to be able to call it when operations inside mongoose blob has ended.
mycallbacktoTopic.find's function). If thecallbackisundefinedit must beundefined. I.e. you're not passing anything toTopicStatistics.createTopicStatistics