title: How to detect MongoDB is open in mongoose
body: <p>All:</p>
  
  <p>I am pretty new to Mongoose, right now, I want to organize my code structure like:</p>
  
  <p>One db config file to init connection:</p>
  
  <pre><code>//db.js
  var mongoose = require('mongoose');
  mongoose.connect('mongodb://localhost/test');
  var db = mongoose.connection;
  db.on('error', console.error.bind(console, 'connection error:'));
  db.once('open', function (callback) {
    // yay!
  });
  module.exports = mongoose;
  </code></pre>
  
  <p>And another file store model:</p>
  
  <pre><code>//model.js
  var mongoose = require("./db");
  var kittySchema = mongoose.Schema({
      name: String
  });
  var Kitten = mongoose.model('Kitten', kittySchema);
  var fluffy = new Kitten({ name: 'fluffy' });
  fluffy.save(function (err, fluffy) {
    if (err) return console.error(err);
    fluffy.speak();
  });
  </code></pre>
  
  <p>What confuses me is: <strong>if I structure the code like this, how can I know the connection is ready in model.js</strong>(I know current async pattern can not guarantee connection is open )</p>
  
  <p>Thanks</p>