1
Guys I want to create a function that returns an array of my database collection, but I need to do this using mongoDB native drive, without Mongoose, I would like some tips. I already have a code, but it doesn’t work:
async function findAll(){
let users = []
connectDB().then( db => {
db.collection('user').find().toArray()
.then(
usersDB => users = usersDB
)
})
return users
}
connectDB function:
async function connectDB() {
const client = await MongoClient.connect(url, {
useNewUrlParser: true,
useUnifiedTopology: true
})
console.log('conectado!')
return client.db(db_name)
}
module.exports = { connectDB }