Node.js 正确使用Mongoskin
我通常和你一起工作,因为我喜欢接近数据库。通常,我使用类似于Node.js 正确使用Mongoskin,node.js,mongodb,coffeescript,mongoskin,Node.js,Mongodb,Coffeescript,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>:<
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'
当我使用本地mongo服务器时,这似乎工作得非常好,我的正常运行时间已经有好几个月了,结果从来没有出现过问题
但是,当我使用remote second时,如果服务器的运行时间超过几分钟,我就会遇到问题-与mongodb的连接似乎丢失,尽管自动重新连接
。我想这是因为localhost
连接从未自动关闭
然而,这让我想到,如果我可能以错误的方式使用了
mongoskin
,或者如果auto\u reconnect
存在一个bug?确保mongoskin使用的是1.0.0或更高版本的驱动程序,当我这样做时,我会得到一个类似\u serverstatus
的错误。
db = require 'db'
users = db.collection 'users'
# Now use the collection in handlers and middleware