سؤال

I usually work with mongoskin because I like to be close to the database. Usually, I do a setup with a file like db.coffee, that contains just this:

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'

Then I use it in my other sources:

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

This seems to work perfectly fine when I am using a local mongo server, I've had an uptime for months and it never turned out to be a problem.

However, when I am using the remote second, I get problem if the server runs longer than just a few minutes - the connection to the mongodb seems lost, despite auto_reconnect. I guess this is because the localhost connection is never closed automatically.

However this led me to thinking if I am maybe using mongoskin in a wrong way, or if there's simply a bug with the auto_reconnect?

هل كانت مفيدة؟

المحلول

ensure mongoskin is using the 1.0.0 or higher driver

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top