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

Closed
thanhthang20 opened this Issue Sep 22, 2013 · 4 comments

Projects

None yet

3 participants

@thanhthang20

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"

image

Thank so much!

@ebensing

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.

@thanhthang20

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?

@ebensing

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.

@YASHVEER321

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