mongodb mongoose connection open callback doesnt get called
<p>I have a MEAN project and this is a snippet from my server.js</p>

<pre><code>var db = require('./config/db');
// url : 'mongodb://localhost/cdnserver'
// results are same for 127.0.0.1 or the machines ip
console.log(mongoose.connect(db.url));

mongoose.set('debug', true);
mongoose.connection.on('connected', function () {
  console.log('Mongoose default connection open to ' + db.url);
});

// If the connection throws an error
mongoose.connection.on('error',function (err) {
  console.log('Mongoose default connection error: ' + err);
});

// When the connection is disconnected
mongoose.connection.on('disconnected', function () {
  console.log('Mongoose default connection disconnected');
});
</code></pre>

<p>This is a setup that has been working well for over 3 months now. Now I am replicating my whole MEAN stack along with database to other machine. I took a <strong>mongodump</strong> and did <strong>mongorestore</strong>. The restored db setup looks fine through mongo from terminal.</p>

<p>However, when starting the server, connection-open callback is not getting called. disconnected and error callbacks are getting called if I stop the mongodb service. How do I debug this further? </p>

<p>I am attaching the console output from both the setups.</p>

<p>Setup 1 : </p>

<pre><code>    Mongoose {
  connections:
   [ NativeConnection {
       base: [Circular],
       collections: {},
       models: {},
       replica: false,
       hosts: null,
       host: 'localhost',
       port: 27017,
       user: undefined,
       pass: undefined,
       name: 'cdnserver',
       options: [Object],
       otherDbs: [],
       _readyState: 2,
       _closeCalled: false,
       _hasOpened: false,
       _listening: false,
       db: [Object] } ],
  plugins: [],
  models: {},
  modelSchemas: {},
  options: { pluralization: true } }
Server up on 80
Mongoose default connection open to mongodb://localhost/cdnserver
1
Mongoose: videos.find({}) { skip: 0, limit: 5, fields: undefined }
</code></pre>

<p>Setup 2: </p>

<pre><code>Mongoose {


connections:
   [ NativeConnection {
       base: [Circular],
       collections: {},
       models: {},
       replica: false,
       hosts: null,
       host: 'localhost',
       port: 27017,
       user: undefined,
       pass: undefined,
       name: 'cdnserver',
       options: [Object],
       otherDbs: [],
       _readyState: 2,
       _closeCalled: false,
       _hasOpened: false,
       _listening: false,
       db: [Object] } ],
  plugins: [],
  models: {},
  modelSchemas: {},
  options: { pluralization: true } }
Server up on 80
1
1
Mongoose default connection disconnected
Mongoose default connection error: Error: connection closed
</code></pre>

<p>cat /var/log/mongodb/mongodb.log shows exactly the same output in both the machines.</p>

<p>Update 1: The setup started working properly out of blue and it stopped again. I am not able to figure out what is making this  happen. </p>