Handling 'error' and 'open' events for mongoose