如何通过MongoDB驱动程序监听连接中断

如何通过MongoDB驱动程序监听连接中断,mongodb,Mongodb,我正在使用nodejsmongo驱动程序连接到mongodb实例。代码如下所示 // Retrieve var MongoClient = require('mongodb').MongoClient; // Connect to the db MongoClient.connect("mongodb://localhost:27017/exampleDb", function(err, db) { ... 如何收听连接中断更改。如果连接中断,我想得到通知。MongoDB nodejs驱动

我正在使用nodejsmongo驱动程序连接到mongodb实例。代码如下所示

// Retrieve
var MongoClient = require('mongodb').MongoClient;

// Connect to the db
MongoClient.connect("mongodb://localhost:27017/exampleDb", function(err, db) {
 ...

如何收听连接中断更改。如果连接中断,我想得到通知。MongoDB nodejs驱动程序是否支持它?

我找到了一种通过驱动程序实现的方法,如下代码所示:

db.on('close', (event)=>{

});
我们可以收听密切相关的活动