node.js - express app listen if mongodb is up and re-establish connection -


i have code opens connection mongodb:

db_connect_mongo = init: (callback) ->   self =   mongo_options = db:       safe: true   mongoose.connect db_url, mongo_options   db = self.db_mongo = mongoose.connection    db.on "error", (error) ->     logger.error "error connecting to: " + db_url, logcategory     callback error, null    db.on "connected", ->     logger.info "successfully connected to: " + db_url, logcategory     callback true, db    db.on "disconnected", ->     logger.info "disconnected database: " + db_url, logcategory  # check , connect redis  exports = module.exports = db_connect_mongo 

i call in app.coffee like:

#connect database dbconnection = require "./utils/dbconnect" dbconnection.init (result) ->   logger.info "database initialized: " + result, logcategory 

when shut down mongo db, info: [database connection] disconnected database: mongodb://127.0.0.1:27017/zmgc-mongo in logger.coffee 'listen' if mongodb comes connection made.

what approach catch events of de/re-connection db?


Comments

Popular posts from this blog

blackberry 10 - how to add multiple markers on the google map just by url? -

php - guestbook returning database data to flash -

delphi - Dynamic file type icon -