I had this same issue and I resolved it by simply removing the “;” at the end of the connection string. So you connection string should just be:
"mongodb+srv://username:password@cluster0.lghcp.mongodb.net/?retryWrites=true&w=majority"
That is without the semi-colon at the end.