title: MongoDB mLab mongoose Node.js driver - connection timeout after a period of idle time?
body: <p>I have a simple <strong>Node.js</strong> that uses <strong>mongoose</strong> to connect with <strong>Mongo</strong> database hosted on <strong>mLab</strong>.</p>
  
  <p>Everything seems working just fine: adding new records, querying for existing stuff.</p>
  
  <p>Only sometimes, after some period of inactivity, when I look at the console I see the following:</p>
  
  <pre><code>events.js:160
        throw er; // Unhandled 'error' event
        ^
  
  Error: connection timeout
      at Db.&lt;anonymous&gt; (___PATH___/node_modules/mongoose/lib/drivers/node-mongodb-native/connection.js:168:17)
      at emitTwo (events.js:106:13)
      at Db.emit (events.js:191:7)
      at Server.listener (___PATH___/node_modules/mongodb/lib/db.js:1786:14)
      at emitOne (events.js:96:13)
      at Server.emit (events.js:188:7)
      at Server.&lt;anonymous&gt; (___PATH___/node_modules/mongodb/lib/server.js:274:14)
      at emitOne (events.js:96:13)
      at Server.emit (events.js:188:7)
      at Pool.&lt;anonymous&gt; (___PATH___/node_modules/mongodb-core/lib/topologies/server.js:334:12)
      at emitOne (events.js:96:13)
      at Pool.emit (events.js:188:7)
      at Connection.&lt;anonymous&gt; (___PATH___/node_modules/mongodb-core/lib/connection/pool.js:270:12)
      at Connection.g (events.js:292:16)
      at emitTwo (events.js:106:13)
      at Connection.emit (events.js:191:7)
  </code></pre>
  
  <p>Right now it doesn't matter that much to me - I can always restart the app. I'm worried that in production it will cause a lot of headaches so I preemptively ask what's the issue here?</p>
  
  <p>Note that initially everything is working fine, it after some time when I get <code>Error: connection timeout</code></p>