Ensuring that mongodb connection is closed after every use