我通常使用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的连接似乎丢失了。我想这是因为localhost
连接永远不会自动关闭。
然而,这让我想到我是否可能以错误的方式使用mongoskin
,或者只是auto_reconnect
的错误?
答案 0 :(得分:1)
确保mongoskin使用1.0.0或更高版本的驱动程序