title: Correct Use of Mongoskin
body: <p>I usually work with <a href="https://github.com/kissjs/node-mongoskin" rel="nofollow"><code>mongoskin</code></a> because I like to be close to the database. Usually, I do a setup with a file like <code>db.coffee</code>, that contains just this:</p>
  
  <pre><code>mongo = require 'mongoskin'
  # either local
  module.exports = mongo.db 'mongodb://localhost/database'
  # or remote
  module.exports = mongo.db 'mongodb://&lt;user&gt;:&lt;pass&gt;@&lt;host&gt;:&lt;port&gt;/&lt;db&gt;?auto_reconnect=true'
  </code></pre>
  
  <p>Then I use it in my other sources:</p>
  
  <pre><code>db = require 'db'
  users = db.collection 'users'
  # Now use the collection in handlers and middleware
  </code></pre>
  
  <p>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.</p>
  
  <p>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 <code>auto_reconnect</code>. I guess this is because the <code>localhost</code> connection is never closed automatically.</p>
  
  <p>However this led me to thinking if I am maybe using <code>mongoskin</code> in a wrong way, or if there's simply a bug with the <code>auto_reconnect</code>?</p>