title: Why am I getting error "Trying to open unclosed connection."?
body: <p>I am trying to connect my node app to mongodb via mongoose. It seems to be working, as I can add documents, but I get the error <code>{ [Error: Trying to open unclosed connection.] state: 2 }</code>.</p>
  
  <p>I created a very simple app, just to make sure everything is working properly before connecting my actual app.</p>
  
  <p>Here is my simple app:</p>
  
  <pre><code>var mongoose = require('mongoose');
  var Schema = mongoose.Schema;
  var timeSchema = new Schema({ timestamp: String });
  var Time = mongoose.model('Time', timeSchema);
  
  mongoose.connect('mongodb://localhost/mydb');
  
  var db = mongoose.connection;
  
  db.on('error', console.error.bind(console, 'connection error: '));
  db.once('open', function () {
  
    var testA = new Test({ timestamp: Date() });
  
  });
  </code></pre>
  
  <p>I also tried adding <code>db.close()</code> to the end, but it made no difference.</p>
  
  <p>This is running on a Ubuntu 14.04 VPS with: </p>
  
  <ul>
  <li>Node.js v0.10.3</li>
  <li>MongoDB 2.6.3</li>
  <li>Mongoose 1.4.21</li>
  </ul>