Model.find().exec(function (err, data) { do something }) #1706

thanhthang20 opened this Issue Sep 22, 2013 · 4 comments


None yet

3 participants


Take a look at "myObject" and "pers"
Why we can not print out the value of "myObject" when it is out side "exec" function. The value of myObject when it out side is "undefined"


Thank so much!


This is a problem in your code logic and callbacks. For all of the console.log calls other than the one directly after myObject is set, they will get called before anything is actually set.


So what should I do if I want do something on return data (likely combine with other data) before responding it to client. Do I need some delay time before get it?


generally, you do what you need to within the callback function. You could theoretically use a time delay, but that is not a good way to do it and unreliable.


You can user waterfall/async method for solve this problem.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment