multy-stub/server/utils/mongo.js
Primakov Alexandr Alexandrovich 4b0d9b4dbc mongoose + tests
2024-10-16 11:06:23 +03:00

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,
}