Middleware for mongoose connect method