21 lines
482 B
TypeScript
21 lines
482 B
TypeScript
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");
|
|
});
|
|
}
|