wiki_ghostguild/app/server/plugins/mongodb.ts

20 lines
516 B
TypeScript

import mongoose from "mongoose";
export default defineNitroPlugin(async () => {
const config = useRuntimeConfig();
try {
await mongoose.connect(config.mongodbUri as string);
console.log("✓ MongoDB connected successfully");
} catch (error) {
console.error("✗ MongoDB connection error:", error);
throw error;
}
// Graceful shutdown
process.on("SIGINT", async () => {
await mongoose.connection.close();
console.log("MongoDB connection closed");
process.exit(0);
});
});