Mongoose.js how to check if connection successful?

Problem

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.

Problem courtesy of: WHITECOLOR

Solution

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

Solution courtesy of: thatmarvin

Discussion

There is currently no discussion for this recipe.

This recipe can be found in it's original form on Stack Over Flow.