()
| 3 | import log from "@/src/utils/logger.ts"; |
| 4 | |
| 5 | export const connectMongoDB = async () => { |
| 6 | if (mongoose.connection.readyState !== 1) { |
| 7 | await mongoose.connect(appConfig.mongoDBUrl!); |
| 8 | } |
| 9 | if (mongoose.connection.readyState !== 1) { |
| 10 | throw new Error("[MongoDB] Failed to connect"); |
| 11 | } |
| 12 | log.info("[MongoDB] Connected"); |
| 13 | }; |
| 14 | |
| 15 | export const disconnectMongoDB = async () => { |
| 16 | await mongoose.disconnect(); |