Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

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

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

thanhthang20 opened this issue Sep 22, 2013 · 4 comments

Comments

@thanhthang20
Copy link

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
Copy link
Contributor

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
Copy link
Author

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
Copy link
Contributor

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
Copy link

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
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants