正确使用Mongoskin

我通常使用mongoskin因为我喜欢靠近数据库。 通常,我使用db.coffee文件进行设置,其中包含以下内容:

 mongo = require 'mongoskin' # either local module.exports = mongo.db 'mongodb://localhost/database' # or remote module.exports = mongo.db 'mongodb://<user>:<pass>@<host>:<port>/<db>?auto_reconnect=true' 

然后我用我的其他来源:

 db = require 'db' users = db.collection 'users' # Now use the collection in handlers and middleware 

当我使用本地mongo服务器时,这似乎工作得很好,我已经有几个月的正常运行时间,而且从来没有成为问题。

但是,当我使用远程秒时,如果服务器运行时间超过几分钟,则会出现问题 – 即使使用auto_reconnect ,与mongodb的连接似乎auto_reconnect丢失。 我想这是因为localhost连接永远不会自动closures。

然而,这导致我想如果我可能使用mongoskin在错误的方式,或者如果只是一个错误与auto_reconnect

确保mongoskin正在使用1.0.0或更高版本的驱动程序