Rework MongoDB client to close connections