How does this function returns null? is it because of the variable scope or execution time of the functions?
async function getBook() {
var book;
await libray.findONe({ cat: 1 }, {}, async (err, res) => {
await section.findONe({ secId: res.secI }, {}, (error, result) => {
book = result;
});
});
book = result;
}
return book;
}
await.awaitonly does something useful when it's awaiting a promise and when you pass a callback to your database functions, they do not return a promise. Please take a second to learn whatawaitreally does and how to use it and how to use promises with your database. You can't just through andawaitin anywhere and expect it to do something useful.