MongoDB.live, free & fully virtual. June 9th - 10th. Register Now

Model.find() returns pending promise , but logs actual collection?

hi

Im trying to get data from my DBatlas cluster with Model.find(), but I think something is not working with my async function. function returns a pending promise but im able to console.log the actual cluster objects. How can I store my collection with node.js ?

async function dbData() {

    try{

        let dbData= await formModel.find({})

        //console.log(dbData) //Console logs succesfully

        return dbData

    }

    catch(err){

        console.log(err)

    }

    

}

This is using MongoDB NodeJS driver:

const MongoClient = require('mongodb').MongoClient;
const client = new MongoClient( 'mongodb://localhost:27017', { useUnifiedTopology: true } );

async function getDocs() {

   try {
       await client.connect()
       coll = await client.db('testDB').collection('testColl')
       cursor = await coll.find({})
       return cursor.toArray()
   } catch (e) {
       console.error('Error:', e)
   }
   finally {
       client.close();
   }		
};

(async function() {
    let docsList = await getDocs()
    console.log('Fetched documents:', docsList)
})();