File tree Expand file tree Collapse file tree 2 files changed +8
-6
lines changed
Expand file tree Collapse file tree 2 files changed +8
-6
lines changed Original file line number Diff line number Diff line change @@ -59,11 +59,13 @@ function _connect (options) {
5959 mongoose . connection . on ( 'error' , dbErr => {
6060 log . warn ( { err : dbErr . message } , 'DB connection error, retrying in 30 seconds' )
6161 isOk = false
62- // reject(dbErr)
63- setTimeout ( function ( ) {
64- mongoose . connect ( dbUri , dbOptions )
65- log . info ( 'Attempting to reconnect' )
66- } , options . reconnectInterval || RECONNECT_TIMEOUT )
62+ // disconnect if connection is still open
63+ mongoose . disconnect ( ) . then ( ( ) => {
64+ setTimeout ( function ( ) {
65+ mongoose . connect ( dbUri , dbOptions )
66+ log . info ( 'Attempting to reconnect' )
67+ } , options . reconnectInterval || RECONNECT_TIMEOUT )
68+ } )
6769 } )
6870
6971 mongoose . connection . on ( 'connected' , ( ) => {
Original file line number Diff line number Diff line change 11{
22 "name" : " kth-node-mongo" ,
3- "version" : " 1.0.3 " ,
3+ "version" : " 1.0.4 " ,
44 "description" : " Database connection module for Node.js applications using Mongoose." ,
55 "main" : " index.js" ,
66 "scripts" : {
You can’t perform that action at this time.
0 commit comments