手动closuresmongod.exe不会使用node-mongodb-native引发错误

这是我在这里的第一篇文章。

我正在学习Node和Mongodb。 我已经安装了node-mongodb本地驱动程序,并发现了一些意想不到的事情。

我的脚本在下面,基于官方教程 。

var test; //short cut for later use require('mongodb').MongoClient.connect("mongodb://localhost:27017/exampleDb", function(err, db) { if (err) {return console.log("some error",err);} console.log("database connected"); test = db.collection('test'); test.find().toArray(function(err, items) { if (err) {console.log("some error");} else {console.log("still connected");} }); }); var rep = function () { setTimeout(function () { test.find().toArray(function(err, items) { if (err) {console.log("some error: " + err);} else {console.log("still connected");} }); rep(); }, 2000); } rep(); 

所以每2秒后,console.log输出“仍然连接”,这是预期的。

如果mongod.exe窗口closures(模拟连接到数据库的连接丢失),我希望在console.log中看到“一些错误”。 但是,不logging错误消息。

当mongod.exe重新启动(模拟重新连接)时,console.log会输出许多 “仍连接”

我一直无法从手册或其他在线资源中find答案。 所以我有两个问题:

1)当前的最佳做法是检测突然的mongodb断开('close'),并且在发生这种断开连接时,是否使用find()查询发出错误?

2)重新连接时,console.log会输出许多相同消息的行,就好像它们在断开连接期间已经排队一样,现在正在被logging。 这是正常的吗? 我可以想到一个真正的生活问题:而不是find(),pipe理员可能使用insert()来添加一些数据。 数据库连接中断,但没有错误消息,所以pipe理员可能会做很多插入(),仍然看不到任何结果。 然后重新连接时,一群插入()查询淹没数据库?

请指出我的无知