This is an interesting issue in that the 'disconnected' event is never triggered when the MongoDB is brought down. We are running MongoDB through a Docker container and running a local node.js file.
We are using the latest Mongoose version 5.7.3.
When we tried an older version 5.0.12 it works. We found a similar issue that was described as being fixed in 5.0.12 from this ticket ("error event not triggered #6131") and indeed in 5.0.12 we did properly receive the 'disconnected' event when we closed the MongoDB container.
So it seems this bug has regressed and is back in latest version
mongoose.connection.on('disconnected', () => { console.log('DISCONNECTED!'); });
This is an interesting issue in that the 'disconnected' event is never triggered when the MongoDB is brought down. We are running MongoDB through a Docker container and running a local node.js file.
We are using the latest Mongoose version 5.7.3.
When we tried an older version 5.0.12 it works. We found a similar issue that was described as being fixed in 5.0.12 from this ticket ("error event not triggered #6131") and indeed in 5.0.12 we did properly receive the 'disconnected' event when we closed the MongoDB container.
So it seems this bug has regressed and is back in latest version
mongoose.connection.on('disconnected', () => { console.log('DISCONNECTED!'); });