Refactor mongo client API to check the connection status and regain if the connection is lost