I have a MEAN project and this is a snippet from my server.js
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'); });
This is a setting that has been running for more than 3 months. Now I am copying my entire MEAN stack along with the database to another machine. I took mongodump and made mongorestore . The restored db setup looks great through mongo from the terminal.
However, when the server starts, the open access call is not called. are disabled and error callbacks are called if I stop the mongodb service. How do I debug this further?
I connect console output from both settings.
Setting 1:
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:
Setting 2:
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
cat / var / log / mongodb / mongodb.log shows exactly the same result on both machines.
Update 1: The setup started working correctly due to the blue color and stopped again. I canβt understand what this does.