Search code examples
javascriptmongodbxmlhttprequest

MongoDB query connection error failing silently due to no connection


How do I handle a mongodb query going unanswered? In my current situation it was as stupid as failing to fire up my local database instance after rebooting my machine, but I could see this happening in the wild.

Ex:The user tries to login, the browser fires an ajax request to the server, the server does it's authentication thing and tries to find the user but... no database, so there is no response. The user stares at their browser in frustration.


Solution

  • If i understand correctly, then simply add Mongod as a service. That way if the server goes down it will restart automatically. For instance in Linux you would issue "sudo chkconfig mongod on". As to the Mongodb just going down first set up your Mongod.conf file with the right parameters for your OS and your requirements (sometimes not as simple as it sounds). Also have your server email you when a critical error happens.

    Hope this helps.