javascript - Calling a parameterized callback function within a mongoose async callback function becomes 'undefined' -


i having weird problem calling callback inside callback mongoose. setup : mean stack.

myfunc = function (cb) {         var projection = {         '_id': 0,         'var1': 1,         'var2': 1     }      var order = {         'var1': 1     }      user.find({})         .select(projection).sort(order)         .exec(function(err, docs){             if(err){                 console.log(err);                 cb(err,docs);             } else {                 console.log(docs);                 cb(err,docs);             }         }); }; 

going lines cb(err,docs) result in "referenceerror: cb not defined"


the weird part have functions deeper nested callbacks can invoke "cb" normaly.

myfunc = function(cb){     model1.count({var1:'test'}, function (err, count) {         if(count) {             model2.findone({dat1:'hoho'}, function (err, doc){                 if (err) {                     console.error(err);                     cb(err,doc);                 } else {                     cb(err,doc);                 }             });                          } else {             cb({message: "no items found"}, null);         }         }) } 

the code above invoked so...

function init(something){     myfunc(function(err, doc) {         if (err){             console.log(err.message);         } else {             //do doc         }     }); } 

ugh, seems calling function did not follow rules.

it called

myfunc(json, function(err,doc){     //do }) 

wrong param count...


Comments

Popular posts from this blog

OpenCV OpenCL: Convert Mat to Bitmap in JNI Layer for Android -

python - How to remove the Xframe Options header in django? -

android - org.xmlpull.v1.XmlPullParserException: expected: START_TAG {http://schemas.xmlsoap.org/soap/envelope/}Envelope -