is there a mongoose connect error callback

后端 未结 6 1406
别那么骄傲
别那么骄傲 2020-11-30 02:42

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 () { ... });
         


        
6条回答
  •  野性不改
    2020-11-30 03:18

    Late answer, but if you want to keep the server running you can use this:

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

提交回复
热议问题