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:
10
server/db.js
10
server/db.js
@@ -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
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user