33 lines
654 B
JavaScript
33 lines
654 B
JavaScript
const MDBClient = require('mongodb').MongoClient
|
|
|
|
const { mongoUrl } = require('./const')
|
|
|
|
const dbInstanses = {
|
|
}
|
|
|
|
const mongoDBConnect = async () => {
|
|
try {
|
|
const MongoClient = new MDBClient(mongoUrl, {
|
|
useUnifiedTopology: true,
|
|
})
|
|
return await MongoClient.connect()
|
|
} catch (error) {
|
|
console.error(error)
|
|
}
|
|
}
|
|
const client = mongoDBConnect()
|
|
|
|
const getDB = async (dbName) => {
|
|
try {
|
|
const cl = await client
|
|
dbInstanses[dbName] = await cl.db(dbName)
|
|
return dbInstanses[dbName]
|
|
} catch (error) {
|
|
console.error(error)
|
|
}
|
|
}
|
|
|
|
module.exports = {
|
|
getDB,
|
|
}
|