MongoParseError: URI does not have hostname, domain name and tld

Solution-1: If you are using any special character in your password you need to encode the particular character as %+ASCII_code_of_the_character below link explains everything. https://docs.atlas.mongodb.com/troubleshoot-connection/#special-characters-in-connection-string-password

Solution-2: Click on auto-generate password and paste it into the connection string, it will work.

screenshot


Ensure special characters in your password are encoded. For example if your password contains '#' you should replace the literal '#' character with '%23' where 23 is the hex code for '#' see: https://docs.atlas.mongodb.com/troubleshoot-connection/#special-characters-in-connection-string-password


You might have special characters in your password string.

E.g. If your password was - password!#, !# are special characters, they would have to be rewritten as %23%21. Thus, your connection string password should be password%23%21.

For more information - MongoDB, ASCII


use '%23' instead of # in your password and

mongoURI = "mongodb+srv://username:[email protected]/dbname?retryWrites=true&w=majority"

mongoose .connect(mongoURI, { useNewUrlParser: true }) .then(() => console.log("MongoDB connected")) .catch((err) => console.log(err));