first commit
This commit is contained in:
20
mongodb/config/index.ts
Normal file
20
mongodb/config/index.ts
Normal file
@@ -0,0 +1,20 @@
|
||||
import mongoose from "mongoose";
|
||||
|
||||
export async function connectMongo() {
|
||||
if (mongoose.connection.readyState === 1) return;
|
||||
|
||||
await mongoose.connect(process.env.MONGO_URI!, {
|
||||
maxPoolSize: 20,
|
||||
serverSelectionTimeoutMS: 5000,
|
||||
});
|
||||
|
||||
console.log("MongoDB connected");
|
||||
|
||||
mongoose.connection.on("error", (err) => {
|
||||
console.error("MongoDB connection error:", err);
|
||||
});
|
||||
|
||||
mongoose.connection.on("disconnected", () => {
|
||||
console.warn("MongoDB disconnected");
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user