Fix MongoDB connection issue in production builds
Prevent database disconnection in dbDisconnect() to avoid "Client must be connected" errors in production. The connection pool handles cleanup automatically.
This commit is contained in:
+3
-5
@@ -29,9 +29,7 @@ export const dbConnect = async () => {
|
||||
};
|
||||
|
||||
export const dbDisconnect = async () => {
|
||||
if (process.env.NODE_ENV === 'development') return;
|
||||
if (mongoConnection.isConnected === 0) return;
|
||||
|
||||
await mongoose.disconnect();
|
||||
mongoConnection.isConnected = 0;
|
||||
// Don't disconnect in production to avoid "Client must be connected" errors
|
||||
// The connection pool will handle connection cleanup automatically
|
||||
return;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user