LaRynk
LaRynk3y ago

✅ – Rinkusu – 17-54 Jun 20

Hi, I'm having troubles assigning the value to this tmp value (it is undefined) outside the find call, any idea please ?
13 Replies
Vanishy
Vanishy3y ago
I dont know whats this .find/.toArray api, but its possible its not finding any values, so res is an empty array, and res[0] is undefined you can console.log(res) to confirm that
LaRynk
LaRynk3y ago
Im using Mongo DB and toArray is just to format the data, forget the [0] thing, I have this much simpler to understand example:
Vanishy
Vanishy3y ago
does the first console.log even run?
LaRynk
LaRynk3y ago
it print TMP OUT then TMP IN with the data, so it's a async problem here the thing is that that does not work:
Vanishy
Vanishy3y ago
looks like youre not awaiting in this code
LaRynk
LaRynk3y ago
Vanishy
Vanishy3y ago
the only reason TMP OUT would print before IN is if you didnt await the promise
LaRynk
LaRynk3y ago
yeah that's why I really don't understand why this aync await does not the job .
Vanishy
Vanishy3y ago
double check your code and run it again 🤷‍♂️
LaRynk
LaRynk3y ago
I'm checking for an hour
LaRynk
LaRynk3y ago
it just ignores the async/await
reactibot
reactibot3y ago
This question has an answer! Thank you for helping 😄 If you have a followup question, you may want to reply to this thread so other members know they're related. https://discord.com/channels/102860784329052160/565213527673929729/988502172759109653 This thread hasn’t had any activity in 12 hours, so it’s now locked. Threads are closed automatically after 12 hours. If you have a followup question, you may want to reply to this thread so other members know they're related. https://discord.com/channels/102860784329052160/565213527673929729/988502172759109653