Mongo DB - MongoParseError

I am trying to establish connection to the Mongo cluster but I get the error:

boilerplate-mongomongoose\node_modules\mongodb-connection-string-url\lib\index.js:86
throw new MongoParseError(‘Invalid scheme, expected connection string to start with “mongodb://” or “mongodb+srv://”’);

As a newbie, I viewed to index.js files to access all possible reasons. I reset my password, checked my URI variabe format, and can’t figure it out. Is there a more consice way to assess the issue?

MONGO_URI=“mongodb://nssensalo:passwordnospecialcharacters@cluster0.qclphvu.mongodb.net/?retryWrites=true&w=majority&appName=Cluster0”

Thanks a bunch!!

It should start with mongodb+srv if you got the connection string from MongoDB Atlas.

How are you getting to the environment variable and using it?

It would help if you posted your full code. Either a GitHub repo, Replit, or share your Gitpod workspace.

Hi!
Thanks for your response.
Here is my github. I forked it and made a seperate branch.

I get the same error message with +srv and without.

Let me know what other info would be helpful to assess where I’m going wrong.

You must have to check that there is unnecessary no space in the URL.

Do you have a .env file in the root folder?

It is good that you didn’t commit it but I also can’t tell if you have it (it must be named .env not sample.env)

I assume you are running this locally?

I do have the .env in the root, and yes running it locally on VSC.

I can’t see the end of the connection string but if you have a semicolon at the end remove it.

So:

MONGO_URI="connectionString"

and not

MONGO_URI="connectionString";

I do not have a semi colon.

Make sure you do not have any spaces at the end as well.

You can try removing the quotes as well but that shouldn’t matter.


Your code from the repo works just fine for me with my own connection string.

I removed the strings to assure I had no spaces and it worked!
I added them back in and the error returned ( single and double quotes ). Wonder why…

Thanks a lot! I didn’t know removing quotes was an option.

Not sure why, it really shouldn’t.

Unless part of your connection string has inner quotes that are maintained and I assume your name and password weren’t the issue, I don’t see anything else in your string that should cause issues (unless I’m blind).

dotenv: What rules does the parsing engine follow?