How to Return mongodb’s Data Call

  mongodb, question
const connect = async () => {
 //Connect mongodb database
 const db = await monguaDb()
 const collection = db.collection('user')
 let b = await collection.find({}).toArray()
 cc = b
 console.log("111---" , cc)
 return b
 }
 
 
 const  a = connect()
 console.log("2222--------", cc)

For example, I want to package mongo to Model …. But I found a problem. There is no problem with printing inside, but when calling outside, the data will be lost. . . . 222——–the printed is empty

Oh, if the project is packaged, the print is Promise {<pending>}

How to deal with it to return the array, or do you need mongose these frameworks?

First of all, I want to declare that this problem has nothing to do with the framework or the library. It is totally a promise problem.
1. It is not data loss, but your cc variable is defined blindly and is not necessary at all.
2. It can be seen that the host does not know enough about promise. await returns the promise object, and the data can be obtained by chain call.

const connect = async () => {
 const db = await monguaDb()
 const collection = db.collection('user')
 let b = await collection.find({}).toArray()
 console.log("111---" , b);
 return b;  //the returned b is a promise object.
 }
 
 Connect().then((doc) => {// retrieve the data of resolve after b completes
 console.log(222---" , doc);
 });