I wrote a small Javascript module to get rows from a MongoDB database:
async function getAll() {
  await mongoose.connect(config.mongoURL).catch(err => { console.log(err); });
  const conn = mongoose.connection;
  conn.collection('healthdata')
    .find({}).toArray().then(result => {
      console.log('=>Docs:', result);
      return result;
   }).catch (err => {
    console.log(err);
   }).finally(() => {
    conn.close();
   });
}
exports.getAll = getAll
I get the correct display from the console ("=>Docs:"). But, when I want to get the result from the following calling function, I get the Undefined value ("Result:"):
app.get("/", async (req, res) => {
  var docs = await db.getAll().then();
  console.log("Result:", docs);
  res.render("index.html");
 });
What is missing? Wrong?
 
     
     
    