This error happens when there is an error connecting to mongodb without an error callback to be called. To fix this error (and get the actual error,) add a callback to the .connect method, or, bind to the error event.
mongoose.connect(config.mongodb, function (err) {
if (err) {
console.log(err);
}
});
or
mongoose.connect(config.mongodb);
var db = mongoose.connection;
db.on('error', function (err) {
console.log('mongodb connection error: %s', err);
process.exit();
});
db.once('open', function () {
console.log('Successfully connected to mongodb');
app.emit('dbopen');
});
If you find that nothing happens and it just hangs, wait 30 or so seconds and it will timeout, which simply means mongoose couldn't connect to mongodb, which could be caused by a very large number of different things, mostly related to network/dns/firewall/server configuration.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…