Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
383 views
in Technique[技术] by (71.8m points)

javascript - is there a mongoose connect error callback

how can i set a callback for the error handling if mongoose isn't able to connect to my DB?

i know of

connection.on('open', function () { ... });

but is there something like

connection.on('error', function (err) { ... });

?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

When you connect you can pick up the error in the callback:

mongoose.connect('mongodb://localhost/dbname', function(err) {
    if (err) throw err;
});

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...