I am new to node js development, recently tried a basic program to connect node js with mongodb. I have used "mongoose" to connect mongodb from node.
I have the following questions before get into the db connections. There are two error case while starting the node app
case 1 - there is an possibility that mongodb not get started, in that case node server it self will not get started. Sample error message is like
mongoose/node_modules/mongodb/lib/server.js:242
process.nextTick(function() { throw err; })
^
Error: connect ECONNREFUSED
at errnoException (net.js:905:11)
at Object.afterConnect [as oncomplete] (net.js:896:19)
[nodemon] app crashed - waiting for file changes before starting...
case 2 - mongodb may be started while starting node app, but it may get disconnected/stopped by some unavoidable situations. in that case if we made any db query, node server get killed. sample error message is like
DisconnectedError: Ran out of retries trying to reconnect to "localhost:27017". Try setting `server.reconnectTries` and `server.reconnectInterval` to something higher.
at MongooseError.DisconnectedError
Please let me know how to handle these two error cases. (some sample code/links would be more helpful)
PS : I tried to surf solution for this, but could not get the proper solution (or) i may be searched with improper keywords!