Database nested query, how to solve the asynchronous problem.

encountered a small problem when practicing:

clipboard.png
videouseruseriduseridavatar,videouser:

clipboard.png

then res.send () will execute before User.findOne () .

how can I execute res.send () after User.findOne () ?

the newcomer at the front end understands Promise and async/await to the extent that he can read it, but cannot write it.

Mengxin asks for advice!

Mar.02,2021

//async function
let videos = await Video.find(...);
for(let video of videos){
  await User.findOne(...)
}
res.send(...)

or execute multiple User.findOne with Promise.all.


there may still be problems after solving the sequence problem. Video should be read-only

MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1b30356-2bcec.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1b30356-2bcec.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?