0
0
mirror of https://github.com/naturalcrit/homebrewery.git synced 2026-01-08 20:23:39 +00:00

Add DB connection/disconnections events to log

This commit is contained in:
G.Ambatte
2025-07-26 14:11:20 +12:00
parent 7af22c9da7
commit 005c05376c

View File

@@ -22,12 +22,21 @@ const handleConnectionError = (error)=>{
} }
}; };
const addListeners = (conn)=>{
conn.connection.on('disconnecting', ()=>{console.log('Mongo disconnecting...');});
conn.connection.on('disconnected', ()=>{console.log('Mongo disconnected!');});
conn.connection.on('connecting', ()=>{console.log('Mongo connecting...');});
conn.connection.on('connected', ()=>{console.log('Mongo connected!');});
return conn;
};
const disconnect = async ()=>{ const disconnect = async ()=>{
return await Mongoose.disconnect(); return await Mongoose.disconnect();
}; };
const connect = async (config)=>{ const connect = async (config)=>{
return await Mongoose.connect(getMongoDBURL(config), { retryWrites: false }) return await Mongoose.connect(getMongoDBURL(config), { retryWrites: false })
.then(addListeners(Mongoose))
.catch((error)=>handleConnectionError(error)); .catch((error)=>handleConnectionError(error));
}; };
@@ -35,3 +44,4 @@ export default {
connect, connect,
disconnect disconnect
}; };