Q:

Mongoose.js how to check if connection successful?

Possible Duplicate:
is there a mongoose connect error callback 

I use mongoose.createConnection to create a connection, it works in async mode.
How to check if connection was successful and how to get error if not?
Thanks.

A:

is there a mongoose connect error callback has a solution, and you can do this too:
mongoose.connection.on('error', function (err) {
 // Do something
});

Source: https://github.com/LearnBoost/mongoose/blob/master/lib/connection.js

